Type Alias WithResult

Source
pub type WithResult<O, T, E> = With<O, Result<T, E>>;
Expand description

A value with Result.

This type implements Deref and DerefMut for the value, therefore it looks like value. But the type provides some Result methods as well.

Aliased Type§

#[repr(C)]
pub struct WithResult<O, T, E> { pub value: O, pub with: Result<T, E>, }

Fields§

§value: O§with: Result<T, E>

Implementations§

Source§

impl<O, T, E> WithResult<O, T, E>

Source

pub fn take(self) -> Result<T, E>

Converts WithResult into Result by unwraping self.

Source

pub const fn is_ok(&self) -> bool

Source

pub fn is_ok_and(self, f: impl FnOnce(T) -> bool) -> bool

Source

pub const fn is_err(&self) -> bool

Source

pub fn is_err_and(self, f: impl FnOnce(E) -> bool) -> bool

Source

pub fn ok(self) -> Option<T>

Source

pub fn err(self) -> Option<E>

Source

pub const fn as_ref(&self) -> Result<&T, &E>

Source

pub fn as_mut(&mut self) -> Result<&mut T, &mut E>

Source

pub fn map<F, U>(self, op: F) -> WithResult<O, U, E>
where F: FnOnce(T) -> U,

Applies the given function to the result. See Result::map.

Source

pub fn map_err<F, D>(self, op: F) -> WithResult<O, T, D>
where F: FnOnce(E) -> D,

Applies the given function to the result. See Result::map_err.

Source

pub fn expect(self, msg: &str) -> T
where E: Debug,

Source

pub fn unwrap(self) -> T
where E: Debug,

Trait Implementations§

Source§

impl<O, T, E> Deref for WithResult<O, T, E>
where E: Debug,

Source§

type Target = O

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<O, T, E> DerefMut for WithResult<O, T, E>
where E: Debug,

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.