You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've started a branch of toml-rs to start working on serde support (as an optional feature), but I must admit I'm pretty lost! I basically just copied over all the tests from the rustc_serialize module to ensure that everything works, and I've got a few problems:
In JSON terms, I've interpreted missing optional fields as None. For example struct Foo { bar: Option<u32> } can be deserialized from the JSON string {}. It looks like #[derive(Deserialize)], however, will unconditionally emit a missing field error in this case. Would it be possible to tweak the derive-mode?
I've also made it such that struct Foo { bar: Vec<u32> } can be deserialized from an empty map (e.g. into an empty Vec for the field bar, which I'm having trouble with for the above reasons.
I had to write my own MapVisitor implementation to not require that every map key is used exhaustively. Is this my own error? If not, could that perhaps be an option on the default MapVisitor?
In general I may just be pretty lost and doing bonkers things in my Deserialize implementation, so any tips would definitely be appreciated!
Ok @oli-obk did some awesome work in toml-rs/toml-rs#61 (thanks!). I haven't yet quite grokked it, but there's only a few remaining things that I've turned up:
Floats are silently casted to integers. There's a test asserting that this occurrence is a type error, but it passes on serde (fails on rustc-serialize). Probably not the end of the world though!
The way enums are deserialized in toml-rs is pretty different from other places. Right now the serializer only supports one piece of payload per variant and then the deserializer for rustc-serialize tries each variant in turn, returning the first one that succeeds. This turns out to be a nice way to encode a field that could have one of multiple forms, and Cargo makes use of this quite heavily. It looks like, however, that the #[derive(Deserialize)] implementation for enums doesn't support this kind of behavior. Right now it expects to learn the variant first and then go forward, but with the current behavior I have it's more of a "let's try something and see if it works"
Activity
vhbit commentedon Apr 2, 2015
any updates on this?
alexcrichton commentedon Apr 3, 2015
I've started a branch of
toml-rsto start working on serde support (as an optional feature), but I must admit I'm pretty lost! I basically just copied over all the tests from therustc_serializemodule to ensure that everything works, and I've got a few problems:None. For examplestruct Foo { bar: Option<u32> }can be deserialized from the JSON string{}. It looks like#[derive(Deserialize)], however, will unconditionally emit a missing field error in this case. Would it be possible to tweak the derive-mode?struct Foo { bar: Vec<u32> }can be deserialized from an empty map (e.g. into an emptyVecfor the fieldbar, which I'm having trouble with for the above reasons.MapVisitorimplementation to not require that every map key is used exhaustively. Is this my own error? If not, could that perhaps be an option on the defaultMapVisitor?In general I may just be pretty lost and doing bonkers things in my
Deserializeimplementation, so any tips would definitely be appreciated!alexcrichton commentedon Apr 21, 2015
Ok @oli-obk did some awesome work in toml-rs/toml-rs#61 (thanks!). I haven't yet quite grokked it, but there's only a few remaining things that I've turned up:
#[derive(Deserialize)]implementation for enums doesn't support this kind of behavior. Right now it expects to learn the variant first and then go forward, but with the current behavior I have it's more of a "let's try something and see if it works"TOML is getting close though!
Merge pull request #1 from serde-rs/dtolnay/serializer
Merge pull request #1 from jbcrail/fix-rational-rounding
Merge pull request #1 from rust-lang/master
Merge pull request #1 from dripton/dripton-extra-parens