diff options
| author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2020-12-04 17:32:26 +0000 |
|---|---|---|
| committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2020-12-04 18:43:02 +0000 |
| commit | b777552167d2651ceb13437f9fde4dca95045912 (patch) | |
| tree | 7c44acdebface1ea343769c9293c0a89ce786f1a /library/std/src/io/buffered | |
| parent | 19c7619dcda902acafa927b0b8511ca8ecce13a4 (diff) | |
| download | rust-b777552167d2651ceb13437f9fde4dca95045912.tar.gz rust-b777552167d2651ceb13437f9fde4dca95045912.zip | |
IntoInnerError: Provide into_error
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Diffstat (limited to 'library/std/src/io/buffered')
| -rw-r--r-- | library/std/src/io/buffered/mod.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/library/std/src/io/buffered/mod.rs b/library/std/src/io/buffered/mod.rs index 0b58e55ed17..65497817f81 100644 --- a/library/std/src/io/buffered/mod.rs +++ b/library/std/src/io/buffered/mod.rs @@ -128,6 +128,27 @@ impl<W> IntoInnerError<W> { } /// Consumes the [`IntoInnerError`] and returns the error which caused the call to + /// [`BufWriter::into_inner()`] to fail. Unlike `error`, this can be used to + /// obtain ownership of the underlying error. + /// + /// # Example + /// ``` + /// #![feature(io_into_inner_error_parts)] + /// use std::io::{BufWriter, ErrorKind, Write}; + /// + /// let mut not_enough_space = [0u8; 10]; + /// let mut stream = BufWriter::new(not_enough_space.as_mut()); + /// write!(stream, "this cannot be actually written").unwrap(); + /// let into_inner_err = stream.into_inner().expect_err("now we discover it's too small"); + /// let err = into_inner_err.into_error(); + /// assert_eq!(err.kind(), ErrorKind::WriteZero); + /// ``` + #[unstable(feature = "io_into_inner_error_parts", issue = "79704")] + pub fn into_error(self) -> Error { + self.1 + } + + /// Consumes the [`IntoInnerError`] and returns the error which caused the call to /// [`BufWriter::into_inner()`] to fail, and the underlying writer. /// /// This can be used to simply obtain ownership of the underlying error; it can also be used for |
