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

Allow Cow<'a, [u8]> to be deserialized even when visitor receives owned bytes. #23

Closed
zakarumych opened this issue Jun 5, 2020 · 3 comments · Fixed by #25
Closed

Allow Cow<'a, [u8]> to be deserialized even when visitor receives owned bytes. #23

zakarumych opened this issue Jun 5, 2020 · 3 comments · Fixed by #25

Comments

@zakarumych
Copy link

Currently Cow<'a, [u8]> uses &'a [u8] deserialization implementation which would fail when deserializing from any non-binary format.
While this is expected for &'a [u8] but Cow<'a, [u8]> can contain Vec<u8> as well and doesn't have to be a pointer into deserializer owned data.

I suggest to write a special visitor for Cow<'a, [u8]> that will create Cow::Borrowed when visit_borrowed_bytes or visit_borrowed_str is called, and Cow::Owned for visit_str, visit_string, visit_bytes or visit_byte_buf.

@zakarumych
Copy link
Author

Probably the same must be done for Cow<'a, Bytes>

@dtolnay
Copy link
Member

dtolnay commented Jun 8, 2020

I would accept a PR to fix this.

@timotree3
Copy link

I have code for this and am working on a PR now.

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