more type aliases
This commit is contained in:
parent
258a2c8f80
commit
a935ba68f5
@ -9,7 +9,7 @@ pub type KeyRc<'a, BT> = Rc<<BT as BinaryTrees<'a>>::Key>;
|
|||||||
|
|
||||||
pub type Split<'a, BT> = (TreeRc<'a, BT>, TreeRc<'a, BT>, KeyRc<'a, BT>);
|
pub type Split<'a, BT> = (TreeRc<'a, BT>, TreeRc<'a, BT>, KeyRc<'a, BT>);
|
||||||
|
|
||||||
pub type Wrapped<'a, BT, A> = <<BT as BinaryTrees<'a>>::T as WeakFunctor>::F<'a, A>;
|
pub type Wrapped<'a, BT, A> = Wrap<'a, A, <BT as BinaryTrees<'a>>::T>;
|
||||||
|
|
||||||
pub trait BinaryTrees<'a>: 'a {
|
pub trait BinaryTrees<'a>: 'a {
|
||||||
type Node: 'a;
|
type Node: 'a;
|
||||||
|
@ -58,7 +58,7 @@ pub trait TraversibleBinaryNode<'a, T: 'a + Monad, A: 'a, D: 'a + PartialEq>: 'a
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait TraversibleBinaryReference<'a, T: 'a + Monad, A: 'a, D: 'a + PartialEq>: 'a {
|
pub trait TraversibleBinaryReference<'a, T: 'a + Monad, A: 'a, D: 'a + PartialEq>: 'a {
|
||||||
fn resolve(&self) -> <T as WeakFunctor>::F<'a, Rc<dyn TraversibleBinaryNode<'a, T, A, D>>>;
|
fn resolve(&self) -> Wrap<'a, Rc<dyn TraversibleBinaryNode<'a, T, A, D>>, T>;
|
||||||
|
|
||||||
/// This should be enough to compare reference for equality.
|
/// This should be enough to compare reference for equality.
|
||||||
fn data(&self) -> D;
|
fn data(&self) -> D;
|
||||||
|
@ -23,7 +23,7 @@ pub struct UnbalancedNode<'a, T: 'a + Monad, A: 'a> {
|
|||||||
key: Rc<A>,
|
key: Rc<A>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type UnbalancedResolution<'a, T, A> = <T as WeakFunctor>::F<'a, Rc<UnbalancedNode<'a, T, A>>>;
|
pub type UnbalancedResolution<'a, T, A> = Wrap<'a, Rc<UnbalancedNode<'a, T, A>>, T>;
|
||||||
|
|
||||||
pub struct UnbalancedReference<'a, T: 'a + Monad, A: 'a>(
|
pub struct UnbalancedReference<'a, T: 'a + Monad, A: 'a>(
|
||||||
Box<dyn 'a + Fn() -> UnbalancedResolution<'a, T, A>>,
|
Box<dyn 'a + Fn() -> UnbalancedResolution<'a, T, A>>,
|
||||||
@ -89,9 +89,7 @@ impl<'a, T: 'a + Monad, A: 'a> TraversibleBinaryNode<'a, T, A, UnbalancedData>
|
|||||||
impl<'a, T: 'a + Monad, A: 'a> TraversibleBinaryReference<'a, T, A, UnbalancedData>
|
impl<'a, T: 'a + Monad, A: 'a> TraversibleBinaryReference<'a, T, A, UnbalancedData>
|
||||||
for UnbalancedReference<'a, T, A>
|
for UnbalancedReference<'a, T, A>
|
||||||
{
|
{
|
||||||
fn resolve(
|
fn resolve(&self) -> Wrap<'a, Rc<dyn TraversibleBinaryNode<'a, T, A, UnbalancedData>>, T> {
|
||||||
&self,
|
|
||||||
) -> <T as WeakFunctor>::F<'a, Rc<dyn TraversibleBinaryNode<'a, T, A, UnbalancedData>>> {
|
|
||||||
<T as Functor>::fmap(
|
<T as Functor>::fmap(
|
||||||
|rc| rc as Rc<dyn TraversibleBinaryNode<'a, T, A, UnbalancedData>>,
|
|rc| rc as Rc<dyn TraversibleBinaryNode<'a, T, A, UnbalancedData>>,
|
||||||
self.0(),
|
self.0(),
|
||||||
|
46
src/func.rs
46
src/func.rs
@ -39,6 +39,8 @@ pub trait WeakFunctor {
|
|||||||
Self: 'a;
|
Self: 'a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type Wrap<'a, A, T> = <T as WeakFunctor>::F<'a, A>;
|
||||||
|
|
||||||
/// Rust-specific implementation of [`Functor`], respecting `move` semantics.
|
/// Rust-specific implementation of [`Functor`], respecting `move` semantics.
|
||||||
///
|
///
|
||||||
/// Cannot insantiate for e.g. multi-element collections:
|
/// Cannot insantiate for e.g. multi-element collections:
|
||||||
@ -276,23 +278,19 @@ pub trait MonadFailAny {
|
|||||||
/// Associated infallible [`Monad`].
|
/// Associated infallible [`Monad`].
|
||||||
type T: Monad;
|
type T: Monad;
|
||||||
|
|
||||||
fn unstuff<'a, A: 'a, E: 'a>(
|
fn unstuff<'a, A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T>
|
||||||
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
|
||||||
) -> <Self::T as WeakFunctor>::F<'a, Result<A, E>>
|
|
||||||
where
|
where
|
||||||
Self: 'a;
|
Self: 'a;
|
||||||
|
|
||||||
fn stuff<'a, A: 'a, E: 'a>(
|
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self>
|
||||||
fa: <Self::T as WeakFunctor>::F<'a, Result<A, E>>,
|
|
||||||
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
|
||||||
where
|
where
|
||||||
Self: 'a;
|
Self: 'a;
|
||||||
|
|
||||||
/// 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: WrapE<'a, A, E0, Self>,
|
||||||
f: impl 'a + FnOnce(E0) -> E1,
|
f: impl 'a + FnOnce(E0) -> E1,
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, E1, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -301,9 +299,9 @@ pub trait MonadFailAny {
|
|||||||
|
|
||||||
/// Equivalent of `catch`/`except`. To inject errors on success, see [`MonadFailAny::bind`].
|
/// Equivalent of `catch`/`except`. To inject errors on success, see [`MonadFailAny::bind`].
|
||||||
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: WrapE<'a, A, E0, Self>,
|
||||||
f: impl 'a + FnOnce(E0) -> <Self::W<E1> as WeakFunctor>::F<'a, A>,
|
f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>,
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, E1, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -319,9 +317,9 @@ pub trait MonadFailAny {
|
|||||||
/// Note: Reasonably it is expected to lack fail semantics for the underlying result.
|
/// Note: Reasonably it is expected to lack fail semantics for the underlying result.
|
||||||
/// Therefore the default implementation descends into the non-fail monad [`MonadFailAny::T`].
|
/// Therefore the default implementation descends into the non-fail monad [`MonadFailAny::T`].
|
||||||
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: WrapE<'a, A, E0, Self>,
|
||||||
f: impl 'a + FnOnce(Result<A, E0>) -> <Self::W<E1> as WeakFunctor>::F<'a, B>,
|
f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>,
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, B>
|
) -> WrapE<'a, B, E1, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -334,8 +332,8 @@ pub trait MonadFailAny {
|
|||||||
///
|
///
|
||||||
/// Note: default implementation doesn't depend on [`Monad::join`].
|
/// Note: default implementation doesn't depend on [`Monad::join`].
|
||||||
fn join<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn join<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wwa: <Self::W<E1> as WeakFunctor>::F<'a, <Self::W<E0> as WeakFunctor>::F<'a, A>>,
|
wwa: WrapE<'a, WrapE<'a, A, E0, Self>, E1, Self>,
|
||||||
) -> <Self::W<Result<E0, E1>> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, Result<E0, E1>, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -347,8 +345,8 @@ pub trait MonadFailAny {
|
|||||||
|
|
||||||
/// Lift the error.
|
/// Lift the error.
|
||||||
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, Result<A, E1>>,
|
wa: WrapE<'a, Result<A, E1>, E0, Self>,
|
||||||
) -> <Self::W<Result<E1, E0>> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, Result<E1, E0>, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -359,15 +357,17 @@ pub trait MonadFailAny {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type WrapE<'a, A, E, Fallible> = Wrap<'a, A, <Fallible as MonadFailAny>::W<E>>;
|
||||||
|
|
||||||
pub trait MonadFailAnyExt: MonadFailAny {
|
pub trait MonadFailAnyExt: MonadFailAny {
|
||||||
fn pure<'a, E: 'a, A: 'a>(a: A) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
fn pure<'a, E: 'a, A: 'a>(a: A) -> WrapE<'a, A, E, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
<Self::W<E> as Pure>::pure(a)
|
<Self::W<E> as Pure>::pure(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fail<'a, E: 'a, A: 'a>(e: E) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
fn fail<'a, E: 'a, A: 'a>(e: E) -> WrapE<'a, A, E, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -375,9 +375,9 @@ pub trait MonadFailAnyExt: MonadFailAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn speculative<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
fn speculative<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
||||||
wwa: <Self::W<E1> as WeakFunctor>::F<'a, <Self::W<E0> as WeakFunctor>::F<'a, A>>,
|
wwa: WrapE<'a, WrapE<'a, A, E0, Self>, E1, Self>,
|
||||||
wwb: <Self::W<E1> as WeakFunctor>::F<'a, <Self::W<E0> as WeakFunctor>::F<'a, B>>,
|
wwb: WrapE<'a, WrapE<'a, B, E0, Self>, E1, Self>,
|
||||||
) -> <Self::W<Result<E0, E1>> as WeakFunctor>::F<'a, (A, B)>
|
) -> WrapE<'a, (A, B), Result<E0, E1>, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ pub enum Selected<'a, A: 'a, B: 'a, T: ?Sized + 'a + WeakFunctor> {
|
|||||||
B(T::F<'a, A>, B),
|
B(T::F<'a, A>, B),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type SelectedWrapped<'a, A, B, T> = <T as WeakFunctor>::F<'a, Selected<'a, A, B, T>>;
|
pub type SelectedWrapped<'a, A, B, T> = Wrap<'a, Selected<'a, A, B, T>, T>;
|
||||||
|
|
||||||
pub trait ApplicativeSelect: Functor {
|
pub trait ApplicativeSelect: Functor {
|
||||||
fn select<'a, A: 'a, B: 'a>(
|
fn select<'a, A: 'a, B: 'a>(
|
||||||
|
@ -73,7 +73,7 @@ impl<
|
|||||||
|
|
||||||
/// Next [Iterative] state, wrapped.
|
/// Next [Iterative] state, wrapped.
|
||||||
pub type IterativeWrapped<'a, F> =
|
pub type IterativeWrapped<'a, F> =
|
||||||
<<F as Iterative<'a>>::T as WeakFunctor>::F<'a, ControlFlow<<F as Iterative<'a>>::B, F>>;
|
Wrap<'a, ControlFlow<<F as Iterative<'a>>::B, F>, <F as Iterative<'a>>::T>;
|
||||||
|
|
||||||
/// Value passed to [`Monad::iterate`].
|
/// Value passed to [`Monad::iterate`].
|
||||||
pub trait Iterative<'a>: 'a + Sized {
|
pub trait Iterative<'a>: 'a + Sized {
|
||||||
|
@ -142,7 +142,7 @@ impl<
|
|||||||
F: Iterative<'a, T = CompositionInstance<U, V>>,
|
F: Iterative<'a, T = CompositionInstance<U, V>>,
|
||||||
> Iterative<'a> for ComposedIterative<F>
|
> Iterative<'a> for ComposedIterative<F>
|
||||||
{
|
{
|
||||||
type B = <V as WeakFunctor>::F<'a, F::B>;
|
type B = Wrap<'a, F::B, V>;
|
||||||
type T = U;
|
type T = U;
|
||||||
|
|
||||||
fn next(self) -> IterativeWrapped<'a, Self> {
|
fn next(self) -> IterativeWrapped<'a, Self> {
|
||||||
|
@ -176,45 +176,7 @@ impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> {
|
|||||||
|
|
||||||
type T = Fallible::W<Ex>;
|
type T = Fallible::W<Ex>;
|
||||||
|
|
||||||
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn unstuff<'a, A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T>
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
|
||||||
f: impl 'a + FnOnce(E0) -> E1,
|
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, A>
|
|
||||||
where
|
|
||||||
Self: 'a,
|
|
||||||
{
|
|
||||||
Fallible::map_err(wa, |err| err.map(f))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
|
||||||
f: impl 'a + FnOnce(E0) -> <Self::W<E1> as WeakFunctor>::F<'a, A>,
|
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, A>
|
|
||||||
where
|
|
||||||
Self: 'a,
|
|
||||||
{
|
|
||||||
Fallible::bind_err(wa, |err| match err {
|
|
||||||
Ok(e0) => f(e0),
|
|
||||||
Err(ex) => Fallible::fail(Err(ex)),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
|
||||||
f: impl 'a + FnOnce(Result<A, E0>) -> <Self::W<E1> as WeakFunctor>::F<'a, B>,
|
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, B>
|
|
||||||
where
|
|
||||||
Self: 'a,
|
|
||||||
{
|
|
||||||
Fallible::bind(wa, |result| match result {
|
|
||||||
Ok(a) => f(Ok(a)),
|
|
||||||
Err(Ok(e0)) => f(Err(e0)),
|
|
||||||
Err(Err(ex)) => Fallible::fail(Err(ex)),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
fn unstuff<'a, A: 'a, E: 'a>(
|
|
||||||
wa: <Self::W<E> as WeakFunctor>::F<'a, A>,
|
|
||||||
) -> <Fallible::W<Ex> as WeakFunctor>::F<'a, Result<A, E>>
|
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
Fallible::W<Ex>: 'a,
|
Fallible::W<Ex>: 'a,
|
||||||
@ -225,9 +187,7 @@ impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stuff<'a, A: 'a, E: 'a>(
|
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self>
|
||||||
fa: <Fallible::W<Ex> as WeakFunctor>::F<'a, Result<A, E>>,
|
|
||||||
) -> <Self::W<E> as WeakFunctor>::F<'a, A>
|
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
Fallible::W<Ex>: 'a,
|
Fallible::W<Ex>: 'a,
|
||||||
@ -238,6 +198,43 @@ impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> {
|
|||||||
Err(ex) => Fallible::fail(Err(ex)),
|
Err(ex) => Fallible::fail(Err(ex)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
|
wa: WrapE<'a, A, E0, Self>,
|
||||||
|
f: impl 'a + FnOnce(E0) -> E1,
|
||||||
|
) -> WrapE<'a, A, E1, Self>
|
||||||
|
where
|
||||||
|
Self: 'a,
|
||||||
|
{
|
||||||
|
Fallible::map_err(wa, |err| err.map(f))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
|
wa: WrapE<'a, A, E0, Self>,
|
||||||
|
f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>,
|
||||||
|
) -> WrapE<'a, A, E1, Self>
|
||||||
|
where
|
||||||
|
Self: 'a,
|
||||||
|
{
|
||||||
|
Fallible::bind_err(wa, |err| match err {
|
||||||
|
Ok(e0) => f(e0),
|
||||||
|
Err(ex) => Fallible::fail(Err(ex)),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
||||||
|
wa: WrapE<'a, A, E0, Self>,
|
||||||
|
f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>,
|
||||||
|
) -> WrapE<'a, B, E1, Self>
|
||||||
|
where
|
||||||
|
Self: 'a,
|
||||||
|
{
|
||||||
|
Fallible::bind(wa, |result| match result {
|
||||||
|
Ok(a) => f(Ok(a)),
|
||||||
|
Err(Ok(e0)) => f(Err(e0)),
|
||||||
|
Err(Err(ex)) => Fallible::fail(Err(ex)),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: SharedFunctor, O: DeriveWeakFunctor> SharedFunctor for OverloadInstance<T, O> {
|
impl<T: SharedFunctor, O: DeriveWeakFunctor> SharedFunctor for OverloadInstance<T, O> {
|
||||||
|
@ -189,10 +189,24 @@ impl MonadFailAny for ResultFailAny {
|
|||||||
|
|
||||||
type T = instances::solo::SoloInstance;
|
type T = instances::solo::SoloInstance;
|
||||||
|
|
||||||
|
fn unstuff<'a, A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T>
|
||||||
|
where
|
||||||
|
Self: 'a,
|
||||||
|
{
|
||||||
|
wa
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self>
|
||||||
|
where
|
||||||
|
Self: 'a,
|
||||||
|
{
|
||||||
|
fa
|
||||||
|
}
|
||||||
|
|
||||||
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: WrapE<'a, A, E0, Self>,
|
||||||
f: impl 'a + FnOnce(E0) -> E1,
|
f: impl 'a + FnOnce(E0) -> E1,
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, E1, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -200,9 +214,9 @@ impl MonadFailAny for ResultFailAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: WrapE<'a, A, E0, Self>,
|
||||||
f: impl 'a + FnOnce(E0) -> <Self::W<E1> as WeakFunctor>::F<'a, A>,
|
f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>,
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, E1, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -210,9 +224,9 @@ impl MonadFailAny for ResultFailAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: WrapE<'a, A, E0, Self>,
|
||||||
f: impl 'a + FnOnce(Result<A, E0>) -> <Self::W<E1> as WeakFunctor>::F<'a, B>,
|
f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>,
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, B>
|
) -> WrapE<'a, B, E1, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -220,8 +234,8 @@ impl MonadFailAny for ResultFailAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, Result<A, E1>>,
|
wa: WrapE<'a, Result<A, E1>, E0, Self>,
|
||||||
) -> <Self::W<Result<E1, E0>> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, Result<E1, E0>, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -231,24 +245,6 @@ impl MonadFailAny for ResultFailAny {
|
|||||||
Err(e) => Err(Err(e)),
|
Err(e) => Err(Err(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,
|
|
||||||
{
|
|
||||||
wa
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
{
|
|
||||||
fa
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ResultFailOver<T: Monad>(T);
|
pub struct ResultFailOver<T: Monad>(T);
|
||||||
@ -258,10 +254,24 @@ impl<T: Monad> MonadFailAny for ResultFailOver<T> {
|
|||||||
|
|
||||||
type T = T;
|
type T = T;
|
||||||
|
|
||||||
|
fn unstuff<'a, A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T>
|
||||||
|
where
|
||||||
|
Self: 'a,
|
||||||
|
{
|
||||||
|
wa
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self>
|
||||||
|
where
|
||||||
|
Self: 'a,
|
||||||
|
{
|
||||||
|
fa
|
||||||
|
}
|
||||||
|
|
||||||
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: WrapE<'a, A, E0, Self>,
|
||||||
f: impl 'a + FnOnce(E0) -> E1,
|
f: impl 'a + FnOnce(E0) -> E1,
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, E1, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -269,9 +279,9 @@ impl<T: Monad> MonadFailAny for ResultFailOver<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: WrapE<'a, A, E0, Self>,
|
||||||
f: impl 'a + FnOnce(E0) -> <Self::W<E1> as WeakFunctor>::F<'a, A>,
|
f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>,
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, E1, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -282,9 +292,9 @@ impl<T: Monad> MonadFailAny for ResultFailOver<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: WrapE<'a, A, E0, Self>,
|
||||||
f: impl 'a + FnOnce(Result<A, E0>) -> <Self::W<E1> as WeakFunctor>::F<'a, B>,
|
f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>,
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, B>
|
) -> WrapE<'a, B, E1, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -292,29 +302,11 @@ impl<T: Monad> MonadFailAny for ResultFailOver<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, Result<A, E1>>,
|
wa: WrapE<'a, Result<A, E1>, E0, Self>,
|
||||||
) -> <Self::W<Result<E1, E0>> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, Result<E1, E0>, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
T::fmap(<ResultFailAny as MonadFailAny>::rotate_out, wa)
|
T::fmap(<ResultFailAny as MonadFailAny>::rotate_out, wa)
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|
||||||
{
|
|
||||||
wa
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
{
|
|
||||||
fa
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -187,10 +187,24 @@ impl MonadFailAny for FutureFailAny {
|
|||||||
|
|
||||||
type T = instances::future::FutureInstance;
|
type T = instances::future::FutureInstance;
|
||||||
|
|
||||||
|
fn unstuff<'a, A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T>
|
||||||
|
where
|
||||||
|
Self: 'a,
|
||||||
|
{
|
||||||
|
wa
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self>
|
||||||
|
where
|
||||||
|
Self: 'a,
|
||||||
|
{
|
||||||
|
fa
|
||||||
|
}
|
||||||
|
|
||||||
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: WrapE<'a, A, E0, Self>,
|
||||||
f: impl 'a + FnOnce(E0) -> E1,
|
f: impl 'a + FnOnce(E0) -> E1,
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, E1, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -198,9 +212,9 @@ impl MonadFailAny for FutureFailAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: WrapE<'a, A, E0, Self>,
|
||||||
f: impl 'a + FnOnce(E0) -> <Self::W<E1> as WeakFunctor>::F<'a, A>,
|
f: impl 'a + FnOnce(E0) -> WrapE<'a, A, E1, Self>,
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, E1, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -213,9 +227,9 @@ impl MonadFailAny for FutureFailAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: WrapE<'a, A, E0, Self>,
|
||||||
f: impl 'a + FnOnce(Result<A, E0>) -> <Self::W<E1> as WeakFunctor>::F<'a, B>,
|
f: impl 'a + FnOnce(Result<A, E0>) -> WrapE<'a, B, E1, Self>,
|
||||||
) -> <Self::W<E1> as WeakFunctor>::F<'a, B>
|
) -> WrapE<'a, B, E1, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -223,8 +237,8 @@ impl MonadFailAny for FutureFailAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>(
|
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, Result<A, E1>>,
|
wa: WrapE<'a, Result<A, E1>, E0, Self>,
|
||||||
) -> <Self::W<Result<E1, E0>> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, Result<E1, E0>, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -236,22 +250,4 @@ impl MonadFailAny for FutureFailAny {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
|
||||||
{
|
|
||||||
wa
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
{
|
|
||||||
fa
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
type Fwa<'a, A, E0, E1, Fallible> = <<Fallible as MonadFailAny>::T as WeakFunctor>::F<
|
type Fwa<'a, A, E0, E1, Fallible> =
|
||||||
'a,
|
Wrap<'a, Result<WrapE<'a, A, E0, Fallible>, E1>, <Fallible as MonadFailAny>::T>;
|
||||||
Result<<<Fallible as MonadFailAny>::W<E0> as WeakFunctor>::F<'a, A>, E1>,
|
|
||||||
>;
|
|
||||||
|
|
||||||
pub trait SpeculativeFail: MonadFailAny {
|
pub trait SpeculativeFail: MonadFailAny {
|
||||||
fn _speculative_a_wb<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
fn _speculative_a_wb<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
||||||
a: Result<A, E0>,
|
a: Result<A, E0>,
|
||||||
wb: Result<<Self::W<E0> as WeakFunctor>::F<'a, B>, E1>,
|
wb: Result<WrapE<'a, B, E0, Self>, E1>,
|
||||||
) -> <Self::W<Result<E0, E1>> as WeakFunctor>::F<'a, (A, B)>
|
) -> WrapE<'a, (A, B), Result<E0, E1>, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -25,7 +23,7 @@ pub trait SpeculativeFail: MonadFailAny {
|
|||||||
fn _speculative_a_fwb<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
fn _speculative_a_fwb<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
||||||
a: Result<A, E0>,
|
a: Result<A, E0>,
|
||||||
fwb: Fwa<'a, B, E0, E1, Self>,
|
fwb: Fwa<'a, B, E0, E1, Self>,
|
||||||
) -> <Self::W<Result<E0, E1>> as WeakFunctor>::F<'a, (A, B)>
|
) -> WrapE<'a, (A, B), Result<E0, E1>, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -35,9 +33,9 @@ pub trait SpeculativeFail: MonadFailAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn _speculative_fa_wb<'a, A: 'a, B: 'a, E0: 'a>(
|
fn _speculative_fa_wb<'a, A: 'a, B: 'a, E0: 'a>(
|
||||||
fa: <Self::T as WeakFunctor>::F<'a, Result<A, E0>>,
|
fa: Wrap<'a, Result<A, E0>, Self::T>,
|
||||||
wb: <Self::W<E0> as WeakFunctor>::F<'a, B>,
|
wb: WrapE<'a, B, E0, Self>,
|
||||||
) -> <Self::W<E0> as WeakFunctor>::F<'a, (A, B)>
|
) -> WrapE<'a, (A, B), E0, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -45,9 +43,9 @@ pub trait SpeculativeFail: MonadFailAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn _speculative_wa_fwb<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
fn _speculative_wa_fwb<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
||||||
wa: <Self::W<E0> as WeakFunctor>::F<'a, A>,
|
wa: WrapE<'a, A, E0, Self>,
|
||||||
fwb: Fwa<'a, B, E0, E1, Self>,
|
fwb: Fwa<'a, B, E0, E1, Self>,
|
||||||
) -> <Self::W<Result<E0, E1>> as WeakFunctor>::F<'a, (A, B)>
|
) -> WrapE<'a, (A, B), Result<E0, E1>, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -70,8 +68,8 @@ pub trait SpeculativeFail: MonadFailAny {
|
|||||||
|
|
||||||
fn _speculative_fwa_wb<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
fn _speculative_fwa_wb<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
||||||
fwa: Fwa<'a, A, E0, E1, Self>,
|
fwa: Fwa<'a, A, E0, E1, Self>,
|
||||||
wb: <Self::W<E0> as WeakFunctor>::F<'a, B>,
|
wb: WrapE<'a, B, E0, Self>,
|
||||||
) -> <Self::W<Result<E0, E1>> as WeakFunctor>::F<'a, (A, B)>
|
) -> WrapE<'a, (A, B), Result<E0, E1>, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
@ -82,9 +80,9 @@ pub trait SpeculativeFail: MonadFailAny {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn speculative<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
fn speculative<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
|
||||||
wwa: <Self::W<E1> as WeakFunctor>::F<'a, <Self::W<E0> as WeakFunctor>::F<'a, A>>,
|
wwa: WrapE<'a, WrapE<'a, A, E0, Self>, E1, Self>,
|
||||||
wwb: <Self::W<E1> as WeakFunctor>::F<'a, <Self::W<E0> as WeakFunctor>::F<'a, B>>,
|
wwb: WrapE<'a, WrapE<'a, B, E0, Self>, E1, Self>,
|
||||||
) -> <Self::W<Result<E0, E1>> as WeakFunctor>::F<'a, (A, B)>
|
) -> WrapE<'a, (A, B), Result<E0, E1>, Self>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
|
11
src/rcore.rs
11
src/rcore.rs
@ -55,7 +55,7 @@ pub trait Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Helper alias for [`WeakFunctor::F`] of [`Context::T`].
|
/// Helper alias for [`WeakFunctor::F`] of [`Context::T`].
|
||||||
pub type Wrapped<'a, Ctx, A> = <<Ctx as Context>::T as WeakFunctor>::F<'a, A>;
|
pub type Wrapped<'a, Ctx, A> = Wrap<'a, A, <Ctx as Context>::T>;
|
||||||
|
|
||||||
/// Fundamental trait for ADN objects.
|
/// Fundamental trait for ADN objects.
|
||||||
pub trait Mentionable<'a, Ctx: 'a + Context>: 'a + Serializable {
|
pub trait Mentionable<'a, Ctx: 'a + Context>: 'a + Serializable {
|
||||||
@ -76,9 +76,10 @@ pub trait Mentionable<'a, Ctx: 'a + Context>: 'a + Serializable {
|
|||||||
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>);
|
fn points_typed(&self, points: &mut impl TakesPoints<'a, Ctx>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type Fctr<'a, Ctx, A> = <A as Mentionable<'a, Ctx>>::Fctr;
|
||||||
|
|
||||||
/// Shorthand for the type of vaalues returned by [`Factory::deserialize`].
|
/// Shorthand for the type of vaalues returned by [`Factory::deserialize`].
|
||||||
pub type ParseResult<'a, Ctx, F> =
|
pub type ParseResult<'a, Ctx, F> = Result<Mtbl<'a, Ctx, F>, <F as Factory<'a, Ctx>>::ParseError>;
|
||||||
Result<<F as Factory<'a, Ctx>>::Mtbl, <F as Factory<'a, Ctx>>::ParseError>;
|
|
||||||
|
|
||||||
/// Trait representing deserialisation rules for [Mentionable]s.
|
/// Trait representing deserialisation rules for [Mentionable]s.
|
||||||
/// Crucial for [`crate::rstd::typeless`].
|
/// Crucial for [`crate::rstd::typeless`].
|
||||||
@ -99,6 +100,10 @@ pub trait Factory<'a, Ctx: 'a + Context>: 'a + Send + Sync + Clone {
|
|||||||
fn unexpected_tail(&self, tail: &[u8]) -> Self::ParseError;
|
fn unexpected_tail(&self, tail: &[u8]) -> Self::ParseError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type Mtbl<'a, Ctx, F> = <F as Factory<'a, Ctx>>::Mtbl;
|
||||||
|
|
||||||
|
pub type ParseError<'a, Ctx, F> = <F as Factory<'a, Ctx>>::ParseError;
|
||||||
|
|
||||||
/// Extension trait for factories.
|
/// Extension trait for factories.
|
||||||
pub trait ExtFactory<'a, Ctx: 'a + Context>: Factory<'a, Ctx> {
|
pub trait ExtFactory<'a, Ctx: 'a + Context>: Factory<'a, Ctx> {
|
||||||
/// Parse the object from a slice.
|
/// Parse the object from a slice.
|
||||||
|
@ -5,7 +5,9 @@ pub trait Origin<'a, Ctx: 'a + Context>: 'a {
|
|||||||
/// Type of the associated object.
|
/// Type of the associated object.
|
||||||
type Mtbl: Mentionable<'a, Ctx>;
|
type Mtbl: Mentionable<'a, Ctx>;
|
||||||
/// Value of the associated factory.
|
/// Value of the associated factory.
|
||||||
fn factory(&self) -> <Self::Mtbl as Mentionable<'a, Ctx>>::Fctr;
|
fn factory(&self) -> OFctr<'a, Ctx, Self>;
|
||||||
/// Try resolving the value.
|
/// Try resolving the value.
|
||||||
fn resolve(self: Rc<Self>) -> Resolution<'a, Ctx, Self::Mtbl>;
|
fn resolve(self: Rc<Self>) -> Resolution<'a, Ctx, Self::Mtbl>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub type OFctr<'a, Ctx, O> = Fctr<'a, Ctx, <O as Origin<'a, Ctx>>::Mtbl>;
|
||||||
|
@ -10,10 +10,8 @@ pub enum ResolutionError<L, P> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// See [`ResolutionResult`].
|
/// See [`ResolutionResult`].
|
||||||
pub type ResolutionFailure<'a, Ctx, A> = ResolutionError<
|
pub type ResolutionFailure<'a, Ctx, A> =
|
||||||
<Ctx as Context>::LookupError<'a>,
|
ResolutionError<<Ctx as Context>::LookupError<'a>, ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>;
|
||||||
<<A as Mentionable<'a, Ctx>>::Fctr as Factory<'a, Ctx>>::ParseError,
|
|
||||||
>;
|
|
||||||
|
|
||||||
/// Result yielded by [`Origin`].
|
/// Result yielded by [`Origin`].
|
||||||
pub type ResolutionResult<'a, Ctx, A> = Result<Rc<A>, ResolutionFailure<'a, Ctx, A>>;
|
pub type ResolutionResult<'a, Ctx, A> = Result<Rc<A>, ResolutionFailure<'a, Ctx, A>>;
|
||||||
|
@ -44,7 +44,7 @@ fn _resolve_origin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
|
|||||||
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Origin<'a, Ctx> for ResolverOrigin<'a, Ctx, F> {
|
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Origin<'a, Ctx> for ResolverOrigin<'a, Ctx, F> {
|
||||||
type Mtbl = F::Mtbl;
|
type Mtbl = F::Mtbl;
|
||||||
|
|
||||||
fn factory(&self) -> <Self::Mtbl as Mentionable<'a, Ctx>>::Fctr {
|
fn factory(&self) -> OFctr<'a, Ctx, Self> {
|
||||||
self.r_factory.clone()
|
self.r_factory.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
src/rstd.rs
26
src/rstd.rs
@ -44,35 +44,23 @@ impl<S: Serializable> ExtSerializable for S {
|
|||||||
pub trait FallibleContext: Context {
|
pub trait FallibleContext: Context {
|
||||||
/// Convert a fallible wrapped into a wrapped result.
|
/// Convert a fallible wrapped into a wrapped result.
|
||||||
fn unstuff<'a, A: 'a, E: 'a>(
|
fn unstuff<'a, A: 'a, E: 'a>(
|
||||||
wa: <<Self::Fallible as MonadFailAny>::W<E> as WeakFunctor>::F<'a, A>,
|
wa: WrapE<'a, A, E, Self::Fallible>,
|
||||||
) -> <Self::T as WeakFunctor>::F<'a, Result<A, E>>
|
) -> Wrap<'a, Result<A, E>, Self::T>
|
||||||
where
|
|
||||||
Self: 'a;
|
|
||||||
|
|
||||||
/// Convert a wrapped result into a fallible wrapped.
|
|
||||||
fn stuff<'a, A: 'a, E: 'a>(
|
|
||||||
fa: <Self::T as WeakFunctor>::F<'a, Result<A, E>>,
|
|
||||||
) -> <<Self::Fallible as MonadFailAny>::W<E> as WeakFunctor>::F<'a, A>
|
|
||||||
where
|
|
||||||
Self: 'a;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Ctx: Context> FallibleContext for Ctx {
|
|
||||||
fn unstuff<'a, A: 'a, E: 'a>(
|
|
||||||
wa: <<Self::Fallible as MonadFailAny>::W<E> as WeakFunctor>::F<'a, A>,
|
|
||||||
) -> <Self::T as WeakFunctor>::F<'a, Result<A, E>>
|
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
Self::Fallible::unstuff(wa)
|
Self::Fallible::unstuff(wa)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert a wrapped result into a fallible wrapped.
|
||||||
fn stuff<'a, A: 'a, E: 'a>(
|
fn stuff<'a, A: 'a, E: 'a>(
|
||||||
fa: <Self::T as WeakFunctor>::F<'a, Result<A, E>>,
|
fa: Wrap<'a, Result<A, E>, Self::T>,
|
||||||
) -> <<Self::Fallible as MonadFailAny>::W<E> as WeakFunctor>::F<'a, A>
|
) -> WrapE<'a, A, E, Self::Fallible>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
Self::Fallible::stuff(fa)
|
Self::Fallible::stuff(fa)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<Ctx: Context> FallibleContext for Ctx {}
|
||||||
|
@ -148,8 +148,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returned by [`TypelessMentionable::cast`].
|
/// Returned by [`TypelessMentionable::cast`].
|
||||||
pub type CastResult<'a, Ctx, A> =
|
pub type CastResult<'a, Ctx, A> = Result<A, ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>;
|
||||||
Result<A, <<A as Mentionable<'a, Ctx>>::Fctr as Factory<'a, Ctx>>::ParseError>;
|
|
||||||
|
|
||||||
impl<'a, Ctx: Context> TypelessMentionable<'a, Ctx>
|
impl<'a, Ctx: Context> TypelessMentionable<'a, Ctx>
|
||||||
where
|
where
|
||||||
|
@ -57,10 +57,7 @@ where
|
|||||||
type B = B;
|
type B = B;
|
||||||
type FA = A::Fctr;
|
type FA = A::Fctr;
|
||||||
type FB = B::Fctr;
|
type FB = B::Fctr;
|
||||||
type ParseError = PairParseError<
|
type ParseError = PairParseError<ParseError<'a, Ctx, A::Fctr>, ParseError<'a, Ctx, B::Fctr>>;
|
||||||
<A::Fctr as Factory<'a, Ctx>>::ParseError,
|
|
||||||
<B::Fctr as Factory<'a, Ctx>>::ParseError,
|
|
||||||
>;
|
|
||||||
|
|
||||||
fn factories(factory_data: &Self::FactoryData) -> (&Self::FA, &Self::FB) {
|
fn factories(factory_data: &Self::FactoryData) -> (&Self::FA, &Self::FB) {
|
||||||
(&factory_data.a, &factory_data.b)
|
(&factory_data.a, &factory_data.b)
|
||||||
@ -72,14 +69,14 @@ where
|
|||||||
|
|
||||||
fn from_error_a(
|
fn from_error_a(
|
||||||
_factory_data: &Self::FactoryData,
|
_factory_data: &Self::FactoryData,
|
||||||
error: <Self::FA as Factory<'a, Ctx>>::ParseError,
|
error: ParseError<'a, Ctx, Self::FA>,
|
||||||
) -> Self::ParseError {
|
) -> Self::ParseError {
|
||||||
PairParseError::A(error)
|
PairParseError::A(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_error_b(
|
fn from_error_b(
|
||||||
_factory_data: &Self::FactoryData,
|
_factory_data: &Self::FactoryData,
|
||||||
error: <Self::FB as Factory<'a, Ctx>>::ParseError,
|
error: ParseError<'a, Ctx, Self::FB>,
|
||||||
) -> Self::ParseError {
|
) -> Self::ParseError {
|
||||||
PairParseError::B(error)
|
PairParseError::B(error)
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,7 @@ use crate::rstd::{fallible::*, *};
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub type TPE<'a, Ctx, A> =
|
pub type TPE<'a, Ctx, A> = TreeParseError<ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>;
|
||||||
TreeParseError<<<A as Mentionable<'a, Ctx>>::Fctr as Factory<'a, Ctx>>::ParseError>;
|
|
||||||
|
|
||||||
pub type TreeFaiure<'a, Ctx, A> =
|
pub type TreeFaiure<'a, Ctx, A> =
|
||||||
ResolutionError<<Ctx as Context>::LookupError<'a>, TPE<'a, Ctx, A>>;
|
ResolutionError<<Ctx as Context>::LookupError<'a>, TPE<'a, Ctx, A>>;
|
||||||
@ -90,9 +89,10 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
|
|||||||
{
|
{
|
||||||
fn resolve(
|
fn resolve(
|
||||||
&self,
|
&self,
|
||||||
) -> <SubsetMonad<'a, Ctx, A> as WeakFunctor>::F<
|
) -> Wrap<
|
||||||
'a,
|
'a,
|
||||||
Rc<dyn TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData>>,
|
Rc<dyn TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData>>,
|
||||||
|
SubsetMonad<'a, Ctx, A>,
|
||||||
> {
|
> {
|
||||||
<SubsetMonad<'a, Ctx, A> as Functor>::fmap(
|
<SubsetMonad<'a, Ctx, A> as Functor>::fmap(
|
||||||
|resolved| resolved as Rc<dyn TraversibleBinaryNode<'a, _, _, _>>,
|
|resolved| resolved as Rc<dyn TraversibleBinaryNode<'a, _, _, _>>,
|
||||||
@ -111,9 +111,10 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
|
|||||||
{
|
{
|
||||||
fn resolve(
|
fn resolve(
|
||||||
&self,
|
&self,
|
||||||
) -> <SubsetMonad<'a, Ctx, A> as WeakFunctor>::F<
|
) -> Wrap<
|
||||||
'a,
|
'a,
|
||||||
Rc<dyn TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData>>,
|
Rc<dyn TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData>>,
|
||||||
|
SubsetMonad<'a, Ctx, A>,
|
||||||
> {
|
> {
|
||||||
<SubsetMonad<'a, Ctx, A> as Functor>::fmap(
|
<SubsetMonad<'a, Ctx, A> as Functor>::fmap(
|
||||||
|resolved| resolved as Rc<dyn TraversibleBinaryNode<'a, _, _, _>>,
|
|resolved| resolved as Rc<dyn TraversibleBinaryNode<'a, _, _, _>>,
|
||||||
@ -132,9 +133,10 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
|
|||||||
{
|
{
|
||||||
fn resolve(
|
fn resolve(
|
||||||
&self,
|
&self,
|
||||||
) -> <SubsetMonad<'a, Ctx, A> as WeakFunctor>::F<
|
) -> Wrap<
|
||||||
'a,
|
'a,
|
||||||
Rc<dyn TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData>>,
|
Rc<dyn TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData>>,
|
||||||
|
SubsetMonad<'a, Ctx, A>,
|
||||||
> {
|
> {
|
||||||
<SubsetMonad<'a, Ctx, A> as Functor>::fmap(
|
<SubsetMonad<'a, Ctx, A> as Functor>::fmap(
|
||||||
|resolved| resolved as Rc<dyn TraversibleBinaryNode<'a, _, _, _>>,
|
|resolved| resolved as Rc<dyn TraversibleBinaryNode<'a, _, _, _>>,
|
||||||
|
@ -80,7 +80,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Factory<'a, Ctx>
|
|||||||
{
|
{
|
||||||
type Mtbl = StackNode<'a, Ctx, A>;
|
type Mtbl = StackNode<'a, Ctx, A>;
|
||||||
|
|
||||||
type ParseError = StackParseError<<A::Fctr as Factory<'a, Ctx>>::ParseError>;
|
type ParseError = StackParseError<ParseError<'a, Ctx, A::Fctr>>;
|
||||||
|
|
||||||
fn deserialize(
|
fn deserialize(
|
||||||
&self,
|
&self,
|
||||||
|
@ -6,4 +6,4 @@ use super::*;
|
|||||||
pub type FallibleMonad<Ctx, E> = <<Ctx as Context>::Fallible as MonadFailAny>::W<E>;
|
pub type FallibleMonad<Ctx, E> = <<Ctx as Context>::Fallible as MonadFailAny>::W<E>;
|
||||||
|
|
||||||
/// Preferred [Wrapped] [Result].
|
/// Preferred [Wrapped] [Result].
|
||||||
pub type FallibleWrapped<'a, Ctx, A, E> = <FallibleMonad<Ctx, E> as WeakFunctor>::F<'a, A>;
|
pub type FallibleWrapped<'a, Ctx, A, E> = Wrap<'a, A, FallibleMonad<Ctx, E>>;
|
||||||
|
@ -131,7 +131,7 @@ impl<P: Error> From<P> for CheckedParseError<P> {
|
|||||||
|
|
||||||
/// Returned by [`CheckedParse::deserialize_checked`].
|
/// Returned by [`CheckedParse::deserialize_checked`].
|
||||||
pub type CheckedParseResult<'a, Ctx, F> =
|
pub type CheckedParseResult<'a, Ctx, F> =
|
||||||
Result<<F as Factory<'a, Ctx>>::Mtbl, CheckedParseError<<F as Factory<'a, Ctx>>::ParseError>>;
|
Result<Mtbl<'a, Ctx, F>, CheckedParseError<ParseError<'a, Ctx, F>>>;
|
||||||
|
|
||||||
/// Extension trait for factories that ensures fixed size read.
|
/// Extension trait for factories that ensures fixed size read.
|
||||||
pub trait CheckedParse<'a, Ctx: 'a + Context>: FixedSizeFactory + Factory<'a, Ctx> {
|
pub trait CheckedParse<'a, Ctx: 'a + Context>: FixedSizeFactory + Factory<'a, Ctx> {
|
||||||
|
@ -50,12 +50,12 @@ pub trait StaticPair<'a, Ctx: 'a + Context>:
|
|||||||
/// Regularise the error returned while parsing the first element.
|
/// Regularise the error returned while parsing the first element.
|
||||||
fn from_error_a(
|
fn from_error_a(
|
||||||
factory_data: &Self::FactoryData,
|
factory_data: &Self::FactoryData,
|
||||||
error: <Self::FA as Factory<'a, Ctx>>::ParseError,
|
error: ParseError<'a, Ctx, Self::FA>,
|
||||||
) -> Self::ParseError;
|
) -> Self::ParseError;
|
||||||
/// Regularise the error returned while parsing the second element.
|
/// Regularise the error returned while parsing the second element.
|
||||||
fn from_error_b(
|
fn from_error_b(
|
||||||
factory_data: &Self::FactoryData,
|
factory_data: &Self::FactoryData,
|
||||||
error: <Self::FB as Factory<'a, Ctx>>::ParseError,
|
error: ParseError<'a, Ctx, Self::FB>,
|
||||||
) -> Self::ParseError;
|
) -> Self::ParseError;
|
||||||
/// Derive factory data from the object data.
|
/// Derive factory data from the object data.
|
||||||
fn factory_data(&self) -> Self::FactoryData;
|
fn factory_data(&self) -> Self::FactoryData;
|
||||||
|
@ -18,25 +18,8 @@ pub trait MappableOrigin<'a, Ctx: 'a + Context>: Origin<'a, Ctx> {
|
|||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ Clone
|
+ Clone
|
||||||
+ Fn(
|
+ Fn(ParseError<'a, Ctx, OFctr<'a, Ctx, Self>>) -> ParseError<'a, Ctx, B::Fctr>,
|
||||||
<<Self::Mtbl as Mentionable<'a, Ctx>>::Fctr as Factory<'a, Ctx>>::ParseError,
|
map_factory: impl 'a + FnOnce(OFctr<'a, Ctx, Self>) -> B::Fctr,
|
||||||
) -> <B::Fctr as Factory<'a, Ctx>>::ParseError,
|
|
||||||
map_factory: impl 'a + FnOnce(<Self::Mtbl as Mentionable<'a, Ctx>>::Fctr) -> B::Fctr,
|
|
||||||
) -> Rc<dyn Origin<'a, Ctx, Mtbl = B>>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, Ctx: 'a + Context, O: ?Sized + Origin<'a, Ctx>> MappableOrigin<'a, Ctx> for O {
|
|
||||||
fn map<B: Mentionable<'a, Ctx>>(
|
|
||||||
self: Rc<Self>,
|
|
||||||
map_ok: impl 'a + Send + Sync + Clone + Fn(Rc<Self::Mtbl>) -> B,
|
|
||||||
map_err: impl 'a
|
|
||||||
+ Send
|
|
||||||
+ Sync
|
|
||||||
+ Clone
|
|
||||||
+ Fn(
|
|
||||||
<<Self::Mtbl as Mentionable<'a, Ctx>>::Fctr as Factory<'a, Ctx>>::ParseError,
|
|
||||||
) -> <B::Fctr as Factory<'a, Ctx>>::ParseError,
|
|
||||||
map_factory: impl 'a + FnOnce(<Self::Mtbl as Mentionable<'a, Ctx>>::Fctr) -> B::Fctr,
|
|
||||||
) -> Rc<dyn Origin<'a, Ctx, Mtbl = B>> {
|
) -> Rc<dyn Origin<'a, Ctx, Mtbl = B>> {
|
||||||
let origin = self.clone();
|
let origin = self.clone();
|
||||||
let origin: WrappedOrigin<'a, Ctx, B> = WrappedOrigin {
|
let origin: WrappedOrigin<'a, Ctx, B> = WrappedOrigin {
|
||||||
@ -52,11 +35,12 @@ impl<'a, Ctx: 'a + Context, O: ?Sized + Origin<'a, Ctx>> MappableOrigin<'a, Ctx>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, Ctx: 'a + Context, O: ?Sized + Origin<'a, Ctx>> MappableOrigin<'a, Ctx> for O {}
|
||||||
|
|
||||||
fn map_resolve<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>>(
|
fn map_resolve<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>>(
|
||||||
resolve: impl 'a + Fn() -> Resolution<'a, Ctx, A>,
|
resolve: impl 'a + Fn() -> Resolution<'a, Ctx, A>,
|
||||||
map_ok: impl 'a + Fn(Rc<A>) -> B,
|
map_ok: impl 'a + Fn(Rc<A>) -> B,
|
||||||
map_err: impl 'a
|
map_err: impl 'a + Fn(ParseError<'a, Ctx, A::Fctr>) -> ParseError<'a, Ctx, B::Fctr>,
|
||||||
+ Fn(<A::Fctr as Factory<'a, Ctx>>::ParseError) -> <B::Fctr as Factory<'a, Ctx>>::ParseError,
|
|
||||||
) -> Resolution<'a, Ctx, B> {
|
) -> Resolution<'a, Ctx, B> {
|
||||||
Ctx::T::fmap(
|
Ctx::T::fmap(
|
||||||
move |resolved| match resolved {
|
move |resolved| match resolved {
|
||||||
@ -80,7 +64,7 @@ struct WrappedOrigin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
|
|||||||
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for WrappedOrigin<'a, Ctx, A> {
|
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for WrappedOrigin<'a, Ctx, A> {
|
||||||
type Mtbl = A;
|
type Mtbl = A;
|
||||||
|
|
||||||
fn factory(&self) -> <Self::Mtbl as Mentionable<'a, Ctx>>::Fctr {
|
fn factory(&self) -> Fctr<'a, Ctx, Self::Mtbl> {
|
||||||
self.w_factory.clone()
|
self.w_factory.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user