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§
Sourcefn 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 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.
Sourcefn catch_error<F>(m: ExceptT<E, MKind, A>, handler: F) -> ExceptT<E, MKind, A>
fn catch_error<F>(m: ExceptT<E, MKind, A>, handler: F) -> ExceptT<E, MKind, A>
Runs m; if it produced Err(e), runs handler(e) instead;
otherwise passes the Ok value through unchanged.
Sourcefn 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,
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".