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

Add Value and implement deserialize_any #53

Merged
merged 11 commits into from
Sep 21, 2017
Merged

Add Value and implement deserialize_any #53

merged 11 commits into from
Sep 21, 2017

Conversation

torkleyy
Copy link
Contributor

@torkleyy torkleyy commented Sep 10, 2017

Fixes #45
Fixes #48

Copy link

@dtolnay dtolnay left a 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.

@torkleyy
Copy link
Contributor Author

@dtolnay Okay. I did it like this because bincode also uses the custom function, but I can change that. That would be a (minor) breaking change though.

@dtolnay
Copy link

dtolnay commented Sep 10, 2017

Oh yeah good point. That may be the same reason Bincode implemented it with custom. I would temporarily do it this way and file a ticket to fix it in the next major release.

Actually we already have a ticket to make it not fail in the first place... #48.

@torkleyy
Copy link
Contributor Author

Yes, that would be better. It would also fix the problem with unused values in RON files raising a "deserialize_any not supported"-error.

@kvark
Copy link
Collaborator

kvark commented Sep 11, 2017

@torkleyy CI fails, please fix.

@torkleyy torkleyy changed the title Replace panic in deserialize_any with error message Add Value and implement deserialize_any Sep 11, 2017
src/de/value.rs Outdated
{
let (value, variant) = data.variant()?;

Ok(Value::Enum(variant, Box::new(value)))
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@kvark
Copy link
Collaborator

kvark commented Sep 11, 2017

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.

@torkleyy
Copy link
Contributor Author

torkleyy commented Sep 11, 2017

@kvark I changed this PR to fix #48

That's why it got that big.

@kvark
Copy link
Collaborator

kvark commented Sep 11, 2017

thanks!
bors r+

bors bot added a commit that referenced this pull request Sep 11, 2017
53: Add Value and implement deserialize_any r=kvark a=torkleyy

Fixes #48
@torkleyy
Copy link
Contributor Author

torkleyy commented Sep 11, 2017

@kvark This isn't meant to be merged yet.

@torkleyy
Copy link
Contributor Author

I still need to implement deserialize_any.

@torkleyy
Copy link
Contributor Author

bors r-

@bors
Copy link
Contributor

bors bot commented Sep 11, 2017

Canceled

@kvark
Copy link
Collaborator

kvark commented Sep 11, 2017

@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.
Edit: also having a commend in the main PR section saying "WIP because: 1. 2. 3. ..." would be great

@kvark kvark changed the title Add Value and implement deserialize_any [WIP] Add Value and implement deserialize_any Sep 11, 2017
@torkleyy
Copy link
Contributor Author

Got the first test implemented and passing!

return visitor.visit_unit();
}

if self.bytes.identifier().is_ok() {
Copy link
Contributor Author

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 :(

Copy link
Contributor Author

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?

Copy link

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.

@torkleyy torkleyy removed the working label Sep 14, 2017
@torkleyy torkleyy changed the title [WIP] Add Value and implement deserialize_any Add Value and implement deserialize_any Sep 14, 2017
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')' {
Copy link
Collaborator

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 )?

Copy link
Contributor Author

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.

@kvark
Copy link
Collaborator

kvark commented Sep 21, 2017

bors r+

bors bot added a commit that referenced this pull request Sep 21, 2017
53: Add Value and implement deserialize_any r=kvark a=torkleyy

Fixes #45
Fixes #48
@bors
Copy link
Contributor

bors bot commented Sep 21, 2017

Build succeeded

@bors bors bot merged commit 4ad391b into ron-rs:master Sep 21, 2017
@torkleyy torkleyy deleted the any branch September 21, 2017 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants