merge MonadFailOver
into FutureFailAny
This commit is contained in:
parent
f22509c199
commit
9a8472e8fd
@ -42,7 +42,7 @@ pub trait Context {
|
|||||||
|
|
||||||
/// Type to allow improved support for result evaluation.
|
/// Type to allow improved support for result evaluation.
|
||||||
/// This is important for async applications stopping early.
|
/// This is important for async applications stopping early.
|
||||||
type Fallible: MonadFailOver<Self::T>;
|
type Fallible: MonadFailAny<T = Self::T>;
|
||||||
|
|
||||||
/// See [`Diagnostic`].
|
/// See [`Diagnostic`].
|
||||||
type D: Diagnostic<Self::T>;
|
type D: Diagnostic<Self::T>;
|
||||||
|
33
src/func.rs
33
src/func.rs
@ -278,6 +278,9 @@ pub trait MonadFailAny {
|
|||||||
/// [`MonadFail`] for a specific error type.
|
/// [`MonadFail`] for a specific error type.
|
||||||
type W<E>: MonadFail<E>;
|
type W<E>: MonadFail<E>;
|
||||||
|
|
||||||
|
/// Associated infallible [`Monad`].
|
||||||
|
type T: Monad;
|
||||||
|
|
||||||
/// Equivalent of [`Result::map_err`].
|
/// Equivalent of [`Result::map_err`].
|
||||||
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
||||||
@ -311,6 +314,17 @@ pub trait MonadFailAny {
|
|||||||
Err(e) => Self::fail(Ok(e)),
|
Err(e) => Self::fail(Ok(e)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
fn unstuff<'a, A: 'a, E: 'a>(
|
||||||
|
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
||||||
|
) -> <Self::T as WeakFunctor>::F<'a, Result<A, E>>
|
||||||
|
where
|
||||||
|
Self: 'a;
|
||||||
|
|
||||||
|
fn stuff<'a, A: 'a, E: 'a>(
|
||||||
|
fa: <Self::T as WeakFunctor>::F<'a, Result<A, E>>,
|
||||||
|
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
||||||
|
where
|
||||||
|
Self: 'a;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MonadFailAnyExt: MonadFailAny {
|
pub trait MonadFailAnyExt: MonadFailAny {
|
||||||
@ -330,25 +344,6 @@ pub trait MonadFailAnyExt: MonadFailAny {
|
|||||||
|
|
||||||
impl<Fallible: ?Sized + MonadFailAny> MonadFailAnyExt for Fallible {}
|
impl<Fallible: ?Sized + MonadFailAny> MonadFailAnyExt for Fallible {}
|
||||||
|
|
||||||
/// Represents a (collection of) [Monad]\(s),
|
|
||||||
/// wrapped values of which are interchangeable with another [Monad]'s
|
|
||||||
/// wrapped [Result]s.
|
|
||||||
pub trait MonadFailOver<T: Monad>: MonadFailAny {
|
|
||||||
fn unstuff<'a, A: 'a, E: 'a>(
|
|
||||||
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
|
||||||
) -> <T as WeakFunctor>::F<'a, Result<A, E>>
|
|
||||||
where
|
|
||||||
Self: 'a,
|
|
||||||
T: 'a;
|
|
||||||
|
|
||||||
fn stuff<'a, A: 'a, E: 'a>(
|
|
||||||
fa: <T as WeakFunctor>::F<'a, Result<A, E>>,
|
|
||||||
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
|
||||||
where
|
|
||||||
Self: 'a,
|
|
||||||
T: 'a;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait SharedFunctor: WeakFunctor {
|
pub trait SharedFunctor: WeakFunctor {
|
||||||
type Shared<'a, A: 'a + Clone>: 'a + Clone
|
type Shared<'a, A: 'a + Clone>: 'a + Clone
|
||||||
where
|
where
|
||||||
|
@ -214,6 +214,8 @@ struct DeriveFailAny<Ex, Fallible>(Ex, Fallible);
|
|||||||
impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> {
|
impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> {
|
||||||
type W<E> = OverloadClass<Fallible::W<Result<E, Ex>>, DeriveFail<Ex>>;
|
type W<E> = OverloadClass<Fallible::W<Result<E, Ex>>, DeriveFail<Ex>>;
|
||||||
|
|
||||||
|
type T = Fallible::W<Ex>;
|
||||||
|
|
||||||
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(E0) -> E1,
|
f: impl 'a + FnOnce(E0) -> E1,
|
||||||
@ -250,9 +252,6 @@ impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> {
|
|||||||
Err(Err(ex)) => Fallible::fail(Err(ex)),
|
Err(Err(ex)) => Fallible::fail(Err(ex)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<Ex, Fallible: MonadFailAny> MonadFailOver<Fallible::W<Ex>> for DeriveFailAny<Ex, Fallible> {
|
|
||||||
fn unstuff<'a, A: 'a, E: 'a>(
|
fn unstuff<'a, A: 'a, E: 'a>(
|
||||||
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
||||||
) -> <Fallible::W<Ex> as WeakFunctor>::F<'a, Result<A, E>>
|
) -> <Fallible::W<Ex> as WeakFunctor>::F<'a, Result<A, E>>
|
||||||
|
@ -215,6 +215,8 @@ impl<'a, A: 'a, E0: 'a> ResultExt<'a, A, E0> for Result<A, E0> {
|
|||||||
impl MonadFailAny for ResultFailAny {
|
impl MonadFailAny for ResultFailAny {
|
||||||
type W<E> = ResultClass<E>;
|
type W<E> = ResultClass<E>;
|
||||||
|
|
||||||
|
type T = classes::solo::SoloClass;
|
||||||
|
|
||||||
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(E0) -> E1,
|
f: impl 'a + FnOnce(E0) -> E1,
|
||||||
@ -257,25 +259,21 @@ impl MonadFailAny for ResultFailAny {
|
|||||||
Err(e) => Err(Err(e)),
|
Err(e) => Err(Err(e)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl MonadFailOver<classes::solo::SoloClass> for ResultFailAny {
|
|
||||||
fn unstuff<'a, A: 'a, E: 'a>(
|
fn unstuff<'a, A: 'a, E: 'a>(
|
||||||
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
||||||
) -> <classes::solo::SoloClass as WeakFunctor>::F<'a, Result<A, E>>
|
) -> <Self::T as WeakFunctor>::F<'a, Result<A, E>>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
classes::solo::SoloClass: 'a,
|
|
||||||
{
|
{
|
||||||
wa
|
wa
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stuff<'a, A: 'a, E: 'a>(
|
fn stuff<'a, A: 'a, E: 'a>(
|
||||||
fa: <classes::solo::SoloClass as WeakFunctor>::F<'a, Result<A, E>>,
|
fa: <Self::T as WeakFunctor>::F<'a, Result<A, E>>,
|
||||||
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
classes::solo::SoloClass: 'a,
|
|
||||||
{
|
{
|
||||||
fa
|
fa
|
||||||
}
|
}
|
||||||
@ -286,6 +284,8 @@ pub struct ResultFailOver<T: Monad>(T);
|
|||||||
impl<T: Monad> MonadFailAny for ResultFailOver<T> {
|
impl<T: Monad> MonadFailAny for ResultFailOver<T> {
|
||||||
type W<E> = super::composition::CompositionClass<T, ResultClass<E>>;
|
type W<E> = super::composition::CompositionClass<T, ResultClass<E>>;
|
||||||
|
|
||||||
|
type T = T;
|
||||||
|
|
||||||
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(E0) -> E1,
|
f: impl 'a + FnOnce(E0) -> E1,
|
||||||
@ -327,25 +327,21 @@ impl<T: Monad> MonadFailAny for ResultFailOver<T> {
|
|||||||
{
|
{
|
||||||
T::fmap(<ResultFailAny as MonadFailAny>::rotate_out, wa)
|
T::fmap(<ResultFailAny as MonadFailAny>::rotate_out, wa)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Monad> MonadFailOver<T> for ResultFailOver<T> {
|
|
||||||
fn unstuff<'a, A: 'a, E: 'a>(
|
fn unstuff<'a, A: 'a, E: 'a>(
|
||||||
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
||||||
) -> <T as WeakFunctor>::F<'a, Result<A, E>>
|
) -> <Self::T as WeakFunctor>::F<'a, Result<A, E>>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
T: 'a,
|
|
||||||
{
|
{
|
||||||
wa
|
wa
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stuff<'a, A: 'a, E: 'a>(
|
fn stuff<'a, A: 'a, E: 'a>(
|
||||||
fa: <T as WeakFunctor>::F<'a, Result<A, E>>,
|
fa: <Self::T as WeakFunctor>::F<'a, Result<A, E>>,
|
||||||
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
T: 'a,
|
|
||||||
{
|
{
|
||||||
fa
|
fa
|
||||||
}
|
}
|
||||||
|
@ -197,6 +197,8 @@ struct FutureFailAny;
|
|||||||
impl MonadFailAny for FutureFailAny {
|
impl MonadFailAny for FutureFailAny {
|
||||||
type W<E> = TryFutureClass<E>;
|
type W<E> = TryFutureClass<E>;
|
||||||
|
|
||||||
|
type T = classes::future::FutureClass;
|
||||||
|
|
||||||
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
||||||
f: impl 'a + FnOnce(E0) -> E1,
|
f: impl 'a + FnOnce(E0) -> E1,
|
||||||
@ -246,25 +248,21 @@ impl MonadFailAny for FutureFailAny {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl MonadFailOver<classes::future::FutureClass> for FutureFailAny {
|
|
||||||
fn unstuff<'a, A: 'a, E: 'a>(
|
fn unstuff<'a, A: 'a, E: 'a>(
|
||||||
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
||||||
) -> <classes::future::FutureClass as WeakFunctor>::F<'a, Result<A, E>>
|
) -> <Self::T as WeakFunctor>::F<'a, Result<A, E>>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
classes::future::FutureClass: 'a,
|
|
||||||
{
|
{
|
||||||
wa
|
wa
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stuff<'a, A: 'a, E: 'a>(
|
fn stuff<'a, A: 'a, E: 'a>(
|
||||||
fa: <classes::future::FutureClass as WeakFunctor>::F<'a, Result<A, E>>,
|
fa: <Self::T as WeakFunctor>::F<'a, Result<A, E>>,
|
||||||
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
classes::future::FutureClass: 'a,
|
|
||||||
{
|
{
|
||||||
fa
|
fa
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user