-
Notifications
You must be signed in to change notification settings - Fork 607
Add helper function to parse stream of json values #24
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
Many modern web APIs return their data as stream of (sometimes newline delimited) JSON values. This commits add handy function `parse_stream` that returns Iterator over parsed values.
should I be worried about failing build on
|
@erickt how does it look? should I fix it for stable? I can't compile crate for stable on my machine (maybe should do some clean), but error from travis ci is |
@little-arhat: Sorry for the delay! I'll review it now. |
json/src/de.rs
Outdated
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.
You should use use std::marker::PhantomData
here.
* `parse_stream` removed in favor of direct `JSONStream` usage; * truncated input no longer silently ignored; * added test for errors; * style violation fixed.
@erickt thanks, fixed all remarks. |
@erickt hey, did you have time to look at updated code? Thanks! |
Fixed some corner cases found during using this. Also, "All checks have passed" — @erickt what do you think? %) |
json/src/de.rs
Outdated
let _:Result<()> = self.deser.parse_whitespace(); | ||
// Since Deserializer.eof() always return Ok(_), it's safe to | ||
// call .ok() here | ||
if self.deser.eof().ok().unwrap() { |
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.
Deserializer.eof
does not always return Ok
there is a try!
in there.
.eof() can return Err, so do not try to unwrap() it unconditionally. Also, check result of .parse_whitespaces(), and report, if there is any errors. (thanks, @nixpulvis)
@nixpulvis you're right, |
@erickt hi, any updates on that? %) |
@little-arhat: Sorry, I've been swamped with trying to get serde 0.7 out the door. That's almost across the line so I'm going to all these outstanding PRs again! |
Many modern web APIs return their data as stream of (sometimes newline
delimited) JSON values. This commits add handy function
parse_stream
that returns Iterator over parsed values.
This feature has some drawbacks or issues:
JSONStream
type, but it seems you cannot currently return abstractIterator
io::Read
, but I couldn't get it to work, unfortunately:expected 'Iter', found
std::io::Bytes`Commit contains tests (and they are passing!)
WDYT?