radn-rs/src/rstd/fallible.rs

26 lines
874 B
Rust

//! Shorthands for using [`Context::Fallible`].
use fail::*;
use crate::func::context::*;
use super::*;
/// Extention trait for simpler conversion between [`FunctorContext::T`] and [`Context::Fallible`].
///
/// Until either Rust type system or [`crate::func`] take serious changes,
/// this is the preferred way to switch between [Wrapped] and [fallible].
pub trait FallibleContext<'a>: FallibleCtx<'a> {
/// Convert a fallible wrapped into a wrapped result.
fn unstuff<A: 'a, E: 'a>(wa: FallibleWrapped<'a, Self, A, E>) -> WrapC<'a, Result<A, E>, Self> {
Self::Fallible::unstuff(wa)
}
/// Convert a wrapped result into a fallible wrapped.
fn stuff<A: 'a, E: 'a>(fa: WrapC<'a, Result<A, E>, Self>) -> FallibleWrapped<'a, Self, A, E> {
Self::Fallible::stuff(fa)
}
}
impl<'a, Ctx: FallibleCtx<'a>> FallibleContext<'a> for Ctx {}