Skip to content

Commit

Permalink
api: add IntoInnerError::into_error
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Bravo555 committed Mar 6, 2023
1 parent f29c9d7 commit e3c663e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ impl<W> IntoInnerError<W> {
&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
Expand Down

0 comments on commit e3c663e

Please sign in to comment.