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

Reader and writer should be taken by value #159

Closed
dtolnay opened this issue Apr 28, 2017 · 3 comments
Closed

Reader and writer should be taken by value #159

dtolnay opened this issue Apr 28, 2017 · 3 comments
Milestone

Comments

@dtolnay
Copy link
Collaborator

@dtolnay dtolnay commented Apr 28, 2017

pub fn deserialize_from<R: ?Sized, T, S>(reader: &mut R, size_limit: S)

pub fn serialize_into<W: ?Sized, T: ?Sized, S>(writer: &mut W, value: &T, size_limit: S)

This is obnoxious when reading or writing some IO stream that is used only for bincode.

bincode::deserialize_from(File::open(f)?, infinite)

The standard library implements Read for &mut R and Write for &mut W so if these methods take the argument by value, callers can keep passing &mut like before if they want.

@TyOverby TyOverby added this to the 1.0 milestone Apr 28, 2017
@TyOverby
Copy link
Collaborator

@TyOverby TyOverby commented Apr 28, 2017

Agree

@fadeevab
Copy link

@fadeevab fadeevab commented Mar 22, 2020

For anyone who wonders what to do now to not move the reader:

let f = File::open(f)?;
bincode::deserialize_from(f.by_ref(), infinite)?; // reference is moved, file is not
bincode::deserialize_from(f.by_ref(), infinite)?; // reference is moved, file is not
bincode::deserialize_from(f, infinite)?; // file is moved, you cannot use one further
@fadeevab

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.