]> git.lizzy.rs Git - rust.git/commitdiff
IntoInnerError: Provide into_error
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 4 Dec 2020 17:32:26 +0000 (17:32 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 4 Dec 2020 18:43:02 +0000 (18:43 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
library/std/src/io/buffered/mod.rs

index 0b58e55ed1731fe9816306fa2cc1088ad8534f8b..65497817f8160d55c688275fbd19763cbbe1dd02 100644 (file)
@@ -127,6 +127,27 @@ pub fn into_inner(self) -> W {
         self.0
     }
 
+    /// 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.
     ///