pub trait ResultExt<T, E> {
// Required method
fn err_kind<K: Into<ErrorKind>>(self, k: K) -> Result<T, ErrorBuilder>
where E: StdError + 'static;
// Provided method
fn err_unknown(self) -> Result<T, ErrorBuilder>
where Self: Sized,
E: StdError + 'static { ... }
}
Expand description
Extension methods for Result
.
Required Methods§
Sourcefn err_kind<K: Into<ErrorKind>>(self, k: K) -> Result<T, ErrorBuilder>where
E: StdError + 'static,
fn err_kind<K: Into<ErrorKind>>(self, k: K) -> Result<T, ErrorBuilder>where
E: StdError + 'static,
Builds an Error
with the given kind, and the original error as source.
Example:
use coded::{Error, ErrorKind, ResultExt};
use std::io::Read;
fn foo() -> Result<(), Error> {
let mut buf = [0u8; 1];
std::io::Cursor::new("").read_exact(&mut buf[..]).err_kind(ErrorKind::Internal)?;
Ok(())
}
assert_eq!(foo().unwrap_err().kind(), coded::ErrorKind::Internal);
Provided Methods§
Sourcefn err_unknown(self) -> Result<T, ErrorBuilder>
fn err_unknown(self) -> Result<T, ErrorBuilder>
Shorthand for err_kind(ErrorKind::Unknown)
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.