From e3c663eecedc2ce4a5529b9326f7e72ead796435 Mon Sep 17 00:00:00 2001 From: Marcel Guzik Date: Mon, 6 Mar 2023 19:25:17 +0100 Subject: [PATCH] api: add IntoInnerError::into_error Currently, for code that doesn't attempt to recover from errors but just reports the error to the caller, it's forced to return the entire `IntoInnerError` even if all one wants is the I/O error. This commit adds `IntoInnerError::into_error` method that consumes `IntoInnerError` and returns contained `io::Error`. This mirrors the API of `std::io::IntoInnerError` in Rust stdlib, which provides such method. PR #304 --- src/error.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/error.rs b/src/error.rs index ae2a6d8..1dfe304 100644 --- a/src/error.rs +++ b/src/error.rs @@ -312,6 +312,15 @@ impl IntoInnerError { &self.err } + /// Consumes the [`IntoInnerError`] and returns the error which caused the + /// call to [`Writer::into_inner`](crate::Writer::into_inner) to fail. + /// + /// Unlike [`IntoInnerError::error`], this can be used to obtain ownership + /// of the underlying error. + pub fn into_error(self) -> io::Error { + self.err + } + /// Returns the underlying writer which generated the error. /// /// The returned value can be used for error recovery, such as