Skip to content

std: Expose get_mut() on I/O wrappers #14785

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

Closed
wants to merge 1 commit into from

Conversation

alexcrichton
Copy link
Member

Currently, it is impossible to reset the timeout on a TCP socket inside of a
buffered writer or a buffered stream. This is because the method requires &mut self, but the buffered objects only provide shared access to the contained
object.

By allowing mutable access, the possibility for corruption of the stream is
exposed. The tradeoff is that many on-the-fly configuration methods are now
possible without having to unwrap the buffered streams.

Currently, it is impossible to reset the timeout on a TCP socket inside of a
buffered writer or a buffered stream. This is because the method requires `&mut
self`, but the buffered objects only provide shared access to the contained
object.

By allowing mutable access, the possibility for corruption of the stream is
exposed. The tradeoff is that many on-the-fly configuration methods are now
possible without having to unwrap the buffered streams.
@brson
Copy link
Contributor

brson commented Jun 10, 2014

I was hitting a similar type-system situation recently where I couldn't call tell while using iterators because I had lost access to the stream.

I wonder if I/O is meant for an interior-mutability world, or if there are some yet-undiscovered Rusty abstractions that would be better for I/O.

Mutating inner I/O objects scares me: is there any chance this could lead to memory unsafety?

@alexcrichton
Copy link
Member Author

This may also mean that some of our signatures are wrong. Perhaps seek should and the property setting flavors should all take &self instead of &mut, only leaving read and write to to taking &mut. Although seeking on a buffered reader could corrupt the buffered state if it didn't know about it...

@aturon
Copy link
Member

aturon commented Jun 10, 2014

cc me

@alexcrichton
Copy link
Member Author

I talked with @aturon tonight at great length about this, and we came to the conclusion that this is likely not the right approach. I will need to think some more before submitting another attempt at this.

@alexcrichton alexcrichton deleted the mut-buffered branch June 11, 2014 08:28
flip1995 added a commit to flip1995/rust that referenced this pull request May 15, 2025
Update "Changelog update walkthrough" section based on
rust-lang/rust-clippy#14748 discussion

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

Successfully merging this pull request may close these issues.

3 participants