Trait ResultExt

Source
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§

Source

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§

Source

fn err_unknown(self) -> Result<T, ErrorBuilder>
where Self: Sized, E: StdError + 'static,

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.

Implementations on Foreign Types§

Source§

impl<T, E: StdError + 'static> ResultExt<T, E> for Result<T, E>

Source§

fn err_kind<K: Into<ErrorKind>>(self, k: K) -> Result<T, ErrorBuilder>

Wraps errors using the given kind.

Implementors§