-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Provide IntoInnerError::into_parts #79673
Conversation
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
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.
I have made this insta-stable since it seems like it will probably be uncontroversial
I agree that having this functionality is definitely uncontroversial, but the exact name and api (return type, order of the elements) could use an unstable period to get some experience and feedback.
Can you open a tracking issue and change this to #[unstable(.., issue = "..")]
? Thanks!
(Edit: Might be good to pick a slightly shorter feature name. ^^ Maybe io_into_inner_error_parts
?)
library/std/src/io/buffered/mod.rs
Outdated
/// let (err, _writer) = into_inner_err.into_parts(); | ||
/// assert_eq!(err.kind(), ErrorKind::WriteZero); |
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.
Can you think of an example where both parts would be used afterwards?
(This example shows there might be a good reason to (also) add a .into_error()
.)
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.
I would be very happy to add .into_error()
too.
For a hypothetical situation where one might want the underlying writer too: perhaps the underlying writer is some kind of network connection which can be reset to a known state and then reused. Eg, maybe the send operation on a TCP socket has timed out and you can recover by advancing the TCP Urgent Data Pointer in the expectation that this will both get the receiver to start discarding data, and then to resynchronise.
Or maybe the underlying writer has interesting state which you want to use for error reporting. Or resources you wish to reuse. Consider a writer which encapsulates an ssh Channel within an owned ssh connection - maybe the write failed because the peer closed the Channel, but you can do something sensible if you can get the ssh connection out of the Channel which involves peeling off the layers.
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.
Oh I'm sure it'll be useful to have both. I was just wondering if we can come up with a minimal example for in te documentation that shows usage of both the writer and the error.
Thanks for the review @m-ou-se.
That makes sense.
Done all that. Thanks for the suggestions. I have done these as git autosquash commits on top of my branch, in the expectation that you'll want me to squash it down later. I also added While doing this I noticed that there is no way to get a failing innner writer out of a |
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.
Nice, thanks!
While doing this I noticed that there is no way to get a failing innner writer out of a
BufWriter
. You can callinto_inner
but it will just keep failing and there is no way to clear or retrieve the data. I will do another MR forBufWriter::into_raw_parts
.
Ah, interesting. Looks like this part of the library hasn't gotten the attention it needs. Thanks for doing this. :)
I wonder if it makes sense to (also?) add a way to get the underlying Writer on IntoInnerError
. Or maybe .into_parts()
should give the buffer and the Writer, instead of the BufWriter? I'll leave that up to you to think about. ^^
I have a few more tiny nits below, after which we can merge this. Feel free to directly squash the commits.
Thanks for the encouragement. That is #79705 now.
Wilco, thanks. |
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
c7800a7
to
9a2b745
Compare
In particular, IntoIneerError only currently provides .error() which returns a reference, not an owned value. This is not helpful and means that a caller of BufWriter::into_inner cannot acquire an owned io::Error which seems quite wrong. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
9a2b745
to
b777552
Compare
I think I've finished messing about with this now, having fixed those nits and squashed it all down. |
Thanks! @bors r+ |
📌 Commit b777552 has been approved by |
☀️ Test successful - checks-actions |
Hi. This is an updated version of the IntoInnerError bits of my previous portmanteau MR #78689. Thanks to @jyn514 and @m-ou-se for helpful comments there.
I have made this insta-stable since it seems like it will probably be uncontroversial, but that is definitely something that someone from the libs API team should be aware of and explicitly consider.
I included a tangentially-related commit providing documentation of the buffer full behaviiour of
&mut [u8] as Write
; the behaviour I am documenting is relied on by the doctest forinto_parts
.