-
Notifications
You must be signed in to change notification settings - Fork 123
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
Add Value and implement deserialize_any #53
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to add an enum variant in Error or ParseError to represent this. custom
is meant for Deserialize impls that have no control over the Deserializer's choice of Error type.
@dtolnay Okay. I did it like this because |
Oh yeah good point. That may be the same reason Bincode implemented it with Actually we already have a ticket to make it not fail in the first place... #48. |
Yes, that would be better. It would also fix the problem with unused values in RON files raising a |
@torkleyy CI fails, please fix. |
src/de/value.rs
Outdated
{ | ||
let (value, variant) = data.variant()?; | ||
|
||
Ok(Value::Enum(variant, Box::new(value))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dtolnay I couldn't figure out how to do deal with enums here yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, there is no way I could even detect an enum, so I removed Value::Enum
.
hmm, do we really need to have 150+ extra lines of code to handle this case? I thought it's just a matter of failing gracefully. |
thanks! |
@kvark This isn't meant to be merged yet. |
I still need to implement |
bors r- |
Canceled |
@torkleyy I see that you used the label to tell that it's still being worked on. I think having a big large WIP in the subject is cleaner. |
Got the first test implemented and passing! |
return visitor.visit_unit(); | ||
} | ||
|
||
if self.bytes.identifier().is_ok() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little bit difficult.. I want to ignore this if it's e.g. the name of a struct, but if we're deserializing a struct, that's a problem (because the field names aren't strings like in JSON, but just unquoted identifiers). This would mean I need context information :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dtolnay Do you have an advice how I could solve that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are 3 ways to store context information:
- In
self
. - Passed as function arguments, for example save the identifier and pass it to the function responsible for deserializing a struct.
- In a new Deserializer that wraps
self
and has additional fields.
src/de/mod.rs
Outdated
@@ -469,10 +469,10 @@ impl<'de, 'a> de::MapAccess<'de> for CommaSeparated<'a, 'de> { | |||
where K: DeserializeSeed<'de> | |||
{ | |||
if self.has_element()? { | |||
if self.terminator == b'}' { | |||
seed.deserialize(&mut *self.de).map(Some) | |||
if self.terminator == b')' { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is MapAccess
separated by )
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's because structs are also considered maps; they share some common logic. That's just a check what it is we're deserializing in order to validate the correctness of the input.
bors r+ |
Build succeeded |
Fixes #45
Fixes #48