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 Deserialize implementation for Bytes #5

Merged
merged 2 commits into from
Sep 8, 2017
Merged

Conversation

hcpl
Copy link
Contributor

@hcpl hcpl commented Sep 8, 2017

The Bytes instance borrows directly from the input source and as such provides a zero-copy interface.

fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Bytes<'de>, E>
where E: Error
{
Ok(Bytes::from(v.as_bytes()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there a default impl forwarding to visit_ borrowed_ bytes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oli-obk visit_borrowed_str docs say that it defauts to visit_str

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. that makes sense

@dtolnay dtolnay merged commit 6a8698c into serde-rs:master Sep 8, 2017
@dtolnay
Copy link
Member

dtolnay commented Sep 8, 2017

Thanks! This was an oversight when updating to Serde 1.0.

I tweaked the error message in 42c1f08 to be consistent with &str. Otherwise formats that do not support borrowing a byte array will produce unhelpful messages that say unexpected type byte array, expected byte array.

Published in serde_bytes 0.10.2.

Thanks for the review @oli-obk!

@hcpl
Copy link
Contributor Author

hcpl commented Sep 8, 2017

Thanks for the quick release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants