devela::code::result

Trait ExtResult

Source
pub trait ExtResult<T, E>: Sealed {
    // Required methods
    fn contains<U: PartialEq<T>>(&self, x: &U) -> bool;
    fn contains_err<F: PartialEq<E>>(&self, f: &F) -> bool;
}
Expand description

Extension trait providing additional methods for Result.

This trait is sealed and cannot be implemented for any other type.

See also ExtOption.

Based on work from:

Required Methods§

Source

fn contains<U: PartialEq<T>>(&self, x: &U) -> bool

Returns true if the result is an Ok value containing the given value.

§Examples
assert_eq!(Ok::<_, ()>(1).contains(&1), true);
assert_eq!(Ok::<_, ()>(1).contains(&2), false);
assert_eq!(Err::<u8, _>("err").contains(&1), false);
Source

fn contains_err<F: PartialEq<E>>(&self, f: &F) -> bool

Returns true if the result is an Err value containing the given value.

§Examples
assert_eq!(Ok::<_, &str>(1).contains_err(&"Some error message"), false);
assert_eq!(Err::<u8, _>("err").contains_err(&"err"), true);
assert_eq!(Err::<u8, _>("err2").contains_err(&"err"), false);

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.

Implementors§

Source§

impl<T, E> ExtResult<T, E> for Result<T, E>