-
Notifications
You must be signed in to change notification settings - Fork 13.3k
serialize: impl ToJson for all Encodables #12936
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
Conversation
I'm a little sad to see yet another encoder in the From what it looks like, the are three different representations that the
This is a bit of a hefty matrix to deal with, and I fear the utility of the
I would imagine that the decoder is what the parser is today, and that this intermediate format of What do you think of this? |
Personally, I was surprised to read in #8335 the need to turn a rust object into a I also think the |
That sounds good to me! Here's a few things that I think would work well:
That way you use the Decoder to go from a string to a rust value and the Encoder to go from a rust value to a string. Conversion between rust values and a Json value would require going through a string. You can also always decode directly into a Json value if you need to inspect the object. |
Why remove the Parser? Looking in |
|
is there any need to keep the If it does stick around, I can't figure out how I would implement impl<D: Decoder> Decodable<D> for Json {
fn (d: &mut D) -> Json {
// can i somehow match against types?
match Decodable::decode(d) {
f64 => Number,
// etc?
}
}
} |
Keeping You don't need to implement |
} | ||
} | ||
|
||
fn into_json(&mut self) -> Json { |
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 should be to_json
instead of into_json
, or instead it should consume self
. We've standardized on using into_
to represent methods that consume self
to transform into the result`. Also, this should return an error type instead of failing.
I'll open a new PR of json cleanup. I've also found the error handler in Encoder's to unfun, so I might fix #12292 before. |
…r_comparison, r=Alexendoo Add MSRV for manual_pattern_char_comparison Fixes rust-lang#12936 changelog: [`manual_pattern_char_comparison`]: Add MSRV 1.58
I just wanted to submit this at this point to see if something like this would be accepted. If so, I can clean it up some more, such as converting to
Vec<T>
, etc.The short is that this is now possible:
fixes #8335