Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialisation of PathBuf doesn't work #53

Closed
neon64 opened this issue Jan 19, 2016 · 2 comments
Closed

Deserialisation of PathBuf doesn't work #53

neon64 opened this issue Jan 19, 2016 · 2 comments

Comments

@neon64
Copy link

@neon64 neon64 commented Jan 19, 2016

Deserialising a simple struct with a PathBuf inside fails with the error: SyntaxError

Can be reproduced by this Gist:
https://gist.github.com/neon64/03230cb40ff3bafed8ee#file-bincode_pathbuf-rs

#![feature(plugin)]
#![feature(custom_derive)]
#![plugin(serde_macros)]

extern crate serde;
extern crate bincode;

use std::path;
use bincode::SizeLimit;
use bincode::serde::{serialize, deserialize};

#[derive(Serialize, Deserialize)]
struct MyData {
    path: path::PathBuf
}

#[test]
fn it_works() {
    let data = MyData {
        path: path::Path::new("foo").to_path_buf()
    };
    let ser = serialize(&data, SizeLimit::Infinite).unwrap();
    let de: MyData = deserialize(&ser).expect("bincode failed");
}

It seems like it is just limited to bincode, as serde_json works for example.

@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Jan 19, 2016

The main issue is that Bincode was built for rustc-serialize, and there are some serde idioms that don't translate well.

The SyntaxError (updated to show useful information in c778cda) is hitting one of the things that bincode can't do. Namely that Bincode does not support Deserializer::visit.

However, PathBuf probably shouldn't require the kind of hinting that Deserializer::visit uses.

Resolutions:

  1. I'll open up a bug on Serde and see if I can get this fixed on their side.
  2. For now, you can just encode / decode using Strings. Sorry about the inconvenience.
@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Feb 7, 2016

This was fixed upstream in serde!

@TyOverby TyOverby closed this Feb 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.