Skip to main content

MonadError

Trait MonadError 

Source
pub trait MonadError<E, A, MKind: Kind1>
where Self: Sized,
{ // Required methods fn throw_error(e: E) -> ExceptT<E, MKind, A> where E: 'static, A: 'static, MKind: Applicative<Result<A, E>> + 'static, MKind::Of<Result<A, E>>: 'static; fn catch_error<F>( m: ExceptT<E, MKind, A>, handler: F, ) -> ExceptT<E, MKind, A> where E: 'static, A: 'static, MKind: Bind<Result<A, E>, Result<A, E>> + Applicative<Result<A, E>> + 'static, MKind::Of<Result<A, E>>: 'static, F: Fn(E) -> ExceptT<E, MKind, A> + Clone + 'static; fn lift_either(r: Result<A, E>) -> ExceptT<E, MKind, A> where E: 'static, A: 'static, MKind: Applicative<Result<A, E>> + 'static, MKind::Of<Result<A, E>>: 'static; }
Expand description

Trait for monads that support throwing and catching errors of type E.

The Except analog of MonadReader (ask/local), MonadState (get/put/…), and MonadWriter (tell/…). The primitive is throw_error; catch_error recovers from a thrown error, and lift_either embeds a pure Result.

throw_error/lift_either need only the inner Applicative; catch_error needs the inner Bind (it must inspect the Result to decide whether to run the handler).

§Type Parameters

  • E: the error type.
  • A: the value type carried by the computation.
  • MKind: the Kind marker for the inner monad.

Required Methods§

Source

fn throw_error(e: E) -> ExceptT<E, MKind, A>
where E: 'static, A: 'static, MKind: Applicative<Result<A, E>> + 'static, MKind::Of<Result<A, E>>: 'static,

Injects an error, short-circuiting: MKind::pure(Err(e)). The primitive.

Source

fn catch_error<F>(m: ExceptT<E, MKind, A>, handler: F) -> ExceptT<E, MKind, A>
where E: 'static, A: 'static, MKind: Bind<Result<A, E>, Result<A, E>> + Applicative<Result<A, E>> + 'static, MKind::Of<Result<A, E>>: 'static, F: Fn(E) -> ExceptT<E, MKind, A> + Clone + 'static,

Runs m; if it produced Err(e), runs handler(e) instead; otherwise passes the Ok value through unchanged.

Source

fn lift_either(r: Result<A, E>) -> ExceptT<E, MKind, A>
where E: 'static, A: 'static, MKind: Applicative<Result<A, E>> + 'static, MKind::Of<Result<A, E>>: 'static,

Embeds a pure Result<A, E> directly: MKind::pure(r).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<E, MKindImpl, A> MonadError<E, A, MKindImpl> for ExceptTKind<E, MKindImpl>
where E: 'static, A: 'static, MKindImpl: Kind1 + 'static,