Monad lift lifetime

This commit is contained in:
AF 2023-05-26 08:52:58 +00:00
parent 859f217902
commit 906e159737
47 changed files with 361 additions and 548 deletions

View File

@ -17,7 +17,7 @@ pub trait BinaryTrees<'a>: 'a {
type Tree: 'a;
type Key: 'a;
type T: 'a + Monad;
type T: Monad<'a>;
fn split(node: Self::Node) -> Wrapped<'a, Self, Split<'a, Self>>;
fn to_tree(node: Self::Node) -> TreeRc<'a, Self>;

View File

@ -51,19 +51,19 @@ pub type Split<'a, T, A, D> = (
Rc<A>,
);
pub trait TraversibleBinaryNode<'a, T: 'a + Monad, A: 'a, D: 'a + PartialEq>: 'a {
pub trait TraversibleBinaryNode<'a, T: Monad<'a>, A: 'a, D: 'a + PartialEq>: 'a {
fn split(&self) -> Split<'a, T, A, D>;
fn to_tree(self: Rc<Self>) -> Rc<dyn TraversibleBinaryTree<'a, T, A, D>>;
}
pub trait TraversibleBinaryReference<'a, T: 'a + Monad, A: 'a, D: 'a + PartialEq>: 'a {
pub trait TraversibleBinaryReference<'a, T: Monad<'a>, A: 'a, D: 'a + PartialEq>: 'a {
fn resolve(&self) -> Wrap<'a, Rc<dyn TraversibleBinaryNode<'a, T, A, D>>, T>;
/// This should be enough to compare reference for equality.
fn data(&self) -> D;
}
pub trait TraversibleBinaryTree<'a, T: 'a + Monad, A: 'a, D: 'a + PartialEq>: 'a {
pub trait TraversibleBinaryTree<'a, T: Monad<'a>, A: 'a, D: 'a + PartialEq>: 'a {
fn refer(&self) -> Option<Rc<dyn TraversibleBinaryReference<'a, T, A, D>>>;
}

View File

@ -1,6 +1,6 @@
use crate::flow::traversible::*;
pub fn n_contains<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
pub fn n_contains<'a, T: MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq>(
comparator: &'a dyn Comparator<A>,
n_set: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>,
key: Rc<A>,
@ -13,7 +13,7 @@ pub fn n_contains<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
}
}
pub fn r_contains<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
pub fn r_contains<'a, T: MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq>(
comparator: &'a dyn Comparator<A>,
r_set: Rc<dyn TraversibleBinaryReference<'a, T, A, D>>,
key: Rc<A>,
@ -21,7 +21,7 @@ pub fn r_contains<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
T::bind(r_set.resolve(), |n_set| n_contains(comparator, n_set, key))
}
pub fn t_contains<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
pub fn t_contains<'a, T: MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq>(
comparator: &'a dyn Comparator<A>,
t_set: Rc<dyn TraversibleBinaryTree<'a, T, A, D>>,
key: Rc<A>,

View File

@ -1,6 +1,6 @@
use crate::flow::traversible::*;
struct SubsetContext<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq> {
struct SubsetContext<'a, T: MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq> {
comparator: &'a dyn Comparator<A>,
n_subset: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>,
n_superset: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>,
@ -11,7 +11,7 @@ struct SubsetContext<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq> {
k_super: Rc<A>,
}
impl<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq> SubsetContext<'a, T, A, D> {
impl<'a, T: 'a + MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq> SubsetContext<'a, T, A, D> {
fn on_l(self, (t_subl, t_subr, k_sub): Split<'a, T, A, D>) -> T::F<'a, ()> {
T::la2(
and,
@ -93,7 +93,7 @@ impl<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq> SubsetContext<'a, T, A
}
}
pub fn n_subset_of_n<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
pub fn n_subset_of_n<'a, T: MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq>(
comparator: &'a dyn Comparator<A>,
n_subset: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>,
n_superset: Rc<dyn TraversibleBinaryNode<'a, T, A, D>>,
@ -124,7 +124,7 @@ pub fn n_subset_of_n<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
.test()
}
pub fn r_subset_of_r<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
pub fn r_subset_of_r<'a, T: MonadFail<'a, ()>, A: 'a, D: 'a + PartialEq>(
comparator: &'a dyn Comparator<A>,
r_subset: Rc<dyn TraversibleBinaryReference<'a, T, A, D>>,
r_superset: Rc<dyn TraversibleBinaryReference<'a, T, A, D>>,
@ -138,7 +138,7 @@ pub fn r_subset_of_r<'a, T: 'a + MonadFail<()>, A: 'a, D: 'a + PartialEq>(
))
}
pub fn t_subset_of_t<'a, T: MonadFail<()>, A, D: 'a + PartialEq>(
pub fn t_subset_of_t<'a, T: MonadFail<'a, ()>, A, D: 'a + PartialEq>(
comparator: &'a dyn Comparator<A>,
t_subset: Rc<dyn TraversibleBinaryTree<'a, T, A, D>>,
t_superset: Rc<dyn TraversibleBinaryTree<'a, T, A, D>>,

View File

@ -17,7 +17,7 @@ impl PartialEq for UnbalancedData {
}
}
pub struct UnbalancedNode<'a, T: 'a + Monad, A: 'a> {
pub struct UnbalancedNode<'a, T: Monad<'a>, A: 'a> {
cl: Rc<UnbalancedTree<'a, T, A>>,
cr: Rc<UnbalancedTree<'a, T, A>>,
key: Rc<A>,
@ -25,16 +25,16 @@ pub struct UnbalancedNode<'a, T: 'a + Monad, A: '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: Monad<'a>, A: 'a>(
Box<dyn 'a + Fn() -> UnbalancedResolution<'a, T, A>>,
);
pub enum UnbalancedTree<'a, T: 'a + Monad, A: 'a> {
pub enum UnbalancedTree<'a, T: Monad<'a>, A: 'a> {
Leaf,
Node(Rc<UnbalancedReference<'a, T, A>>),
}
impl<'a, T: 'a + Monad, A: 'a + Display> Display for UnbalancedNode<'a, T, A>
impl<'a, T: Monad<'a>, A: 'a + Display> Display for UnbalancedNode<'a, T, A>
where
UnbalancedReference<'a, T, A>: std::fmt::Display,
{
@ -43,7 +43,7 @@ where
}
}
impl<'a, T: 'a + Monad, A: 'a + Display> Display for UnbalancedTree<'a, T, A>
impl<'a, T: Monad<'a>, A: 'a + Display> Display for UnbalancedTree<'a, T, A>
where
UnbalancedReference<'a, T, A>: std::fmt::Display,
{
@ -72,7 +72,7 @@ impl<'a, A: 'a + Display> Display
}
}
impl<'a, T: 'a + Monad, A: 'a> TraversibleBinaryNode<'a, T, A, UnbalancedData>
impl<'a, T: Monad<'a>, A: 'a> TraversibleBinaryNode<'a, T, A, UnbalancedData>
for UnbalancedNode<'a, T, A>
{
fn split(&self) -> Split<'a, T, A, UnbalancedData> {
@ -86,7 +86,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: Monad<'a>, A: 'a> TraversibleBinaryReference<'a, T, A, UnbalancedData>
for UnbalancedReference<'a, T, A>
{
fn resolve(&self) -> Wrap<'a, Rc<dyn TraversibleBinaryNode<'a, T, A, UnbalancedData>>, T> {
@ -101,7 +101,7 @@ impl<'a, T: 'a + Monad, A: 'a> TraversibleBinaryReference<'a, T, A, UnbalancedDa
}
}
impl<'a, T: 'a + Monad, A: 'a> TraversibleBinaryTree<'a, T, A, UnbalancedData>
impl<'a, T: Monad<'a>, A: 'a> TraversibleBinaryTree<'a, T, A, UnbalancedData>
for UnbalancedTree<'a, T, A>
{
fn refer(&self) -> Option<Rc<dyn TraversibleBinaryReference<'a, T, A, UnbalancedData>>> {
@ -116,11 +116,11 @@ type WrapType<'a, T, A> = Box<
dyn 'a + Fn(Rc<UnbalancedNode<'a, T, A>>) -> Box<dyn Fn() -> UnbalancedResolution<'a, T, A>>,
>;
pub struct UnbalancedConstructor<'a, T: 'a + Monad, A: 'a> {
pub struct UnbalancedConstructor<'a, T: Monad<'a>, A: 'a> {
wrap: WrapType<'a, T, A>,
}
impl<'a, T: 'a + Monad, A: 'a> UnbalancedConstructor<'a, T, A> {
impl<'a, T: Monad<'a>, A: 'a> UnbalancedConstructor<'a, T, A> {
pub fn rc(wrap: WrapType<'a, T, A>) -> Rc<Self> {
Self { wrap }.into()
}

View File

@ -45,7 +45,7 @@ pub trait WeakFunctorA<'a>: 'a {
type Fa<A: 'a>: 'a;
}
impl<'a, T: 'a + WeakFunctor> WeakFunctorA<'a> for T {
impl<'a, T: ?Sized + 'a + WeakFunctor> WeakFunctorA<'a> for T {
type Fa<A: 'a> = T::F<'a, A>;
}
@ -184,35 +184,28 @@ pub trait Applicative:
/// Equivalent of Haskell's `Monad`.
///
/// <https://hackage.haskell.org/package/base-4.18.0.0/docs/Control-Monad.html>
pub trait Monad: Applicative {
pub trait Monad<'a>: 'a + Applicative {
/// Equivalent of Haskell's `>==`.
/// Due to Rust limitations, it's not a `function->function` conversion.
/// For that see [`derivations::bind`].
fn bind<'a, A: 'a, B: 'a>(
fn bind<A: 'a, B: 'a>(
fa: Self::F<'a, A>,
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
) -> Self::F<'a, B>
where
Self: 'a;
) -> Self::F<'a, B>;
/// Included for optimisation and clarity.
/// Generally, [`Monad::bind`] should be enough implement it.
/// See [`StacklessInstance::iterate`] for a generic, though less-than ideal, blanket implementation.
/// On practice, you generally shouldn't be using [`Monad::bind`]/[`Pure::pure`]/[`Functor::fmap`] here.
fn iterate<'a, B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
where
Self: 'a;
fn iterate<B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>;
/// Equivalent of Haskell's `join`.
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A>
where
Self: 'a,
{
fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
Self::bind(ffa, |fa| fa)
}
}
pub trait MonadExt<'a>: 'a + Monad {
pub trait MonadExt<'a>: Monad<'a> {
/// [`FnMut`] version of [`Monad::iterate`].
/// Reasoning for this method existing at all is that
/// most usecases are better modelled with [`FnMut`]
@ -225,23 +218,20 @@ pub trait MonadExt<'a>: 'a + Monad {
}
}
impl<'a, T: 'a + Monad> MonadExt<'a> for T {}
impl<'a, T: Monad<'a>> MonadExt<'a> for T {}
/// Part of [`MonadFail`] responsible for Haskell's `fail`.
pub trait Fail<E>: WeakFunctor {
pub trait Fail<'a, E: 'a>: 'a + WeakFunctor {
/// Equivalent of Haskell's `fail`.
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
where
Self: 'a,
E: 'a;
fn fail<A: 'a>(e: E) -> Self::F<'a, A>;
}
/// Equivalent of Haskell's `MonadFail`. Auto-implemented for all [`Fail`]`+`[`Monad`].
///
/// <https://hackage.haskell.org/package/base-4.18.0.0/docs/Control-Monad.html>
pub trait MonadFail<E>: Monad + Fail<E> {}
pub trait MonadFail<'a, E: 'a>: Monad<'a> + Fail<'a, E> {}
impl<E, T: Monad + Fail<E>> MonadFail<E> for T {}
impl<'a, E: 'a, T: Monad<'a> + Fail<'a, E>> MonadFail<'a, E> for T {}
/// Represents wrapped results which are instantly available.
pub trait LocalFunctor: WeakFunctor {
@ -262,40 +252,32 @@ pub trait LocalFunctor: WeakFunctor {
}
/// Represents a (collection of) [Monad]\(s) that can hold any type of error.
pub trait MonadFailAny {
pub trait MonadFailAny<'a>: 'a {
/// [`MonadFail`] for a specific error type.
type W<E>: MonadFail<E>;
type W<E>: MonadFail<'a, E>
where
E: 'a;
/// Associated infallible [`Monad`].
type T: Monad;
type T: Monad<'a>;
fn unstuff<'a, A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T>
where
Self: 'a;
fn unstuff<A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T>;
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self>
where
Self: 'a;
fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self>;
/// Equivalent of [`Result::map_err`].
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
fn map_err<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,
{
) -> WrapE<'a, A, E1, Self> {
Self::bind_err(wa, |e0| Self::fail(f(e0)))
}
/// 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, 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,
{
) -> WrapE<'a, A, E1, Self> {
Self::bind(wa, |result| match result {
Ok(a) => Self::pure(a),
Err(e0) => f(e0),
@ -307,13 +289,10 @@ pub trait MonadFailAny {
///
/// 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`].
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
fn bind<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,
{
) -> WrapE<'a, B, E1, Self> {
Self::stuff(<Self::T as Monad>::bind(Self::unstuff(wa), |result| {
Self::unstuff(f(result))
}))
@ -322,12 +301,9 @@ pub trait MonadFailAny {
/// Equivalent of [`Monad::join`], flattening the errors.
///
/// Note: default implementation doesn't depend on [`Monad::join`].
fn join<'a, A: 'a, E0: 'a, E1: 'a>(
fn join<A: 'a, E0: 'a, E1: 'a>(
wwa: WrapE<'a, WrapE<'a, A, E0, Self>, E1, Self>,
) -> WrapE<'a, A, Result<E0, E1>, Self>
where
Self: 'a,
{
) -> WrapE<'a, A, Result<E0, E1>, Self> {
Self::bind(wwa, |result| match result {
Ok(wa) => Self::map_err(wa, Ok),
Err(e1) => Self::fail(Err(e1)),
@ -335,12 +311,9 @@ pub trait MonadFailAny {
}
/// Lift the error.
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>(
fn rotate_out<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, Result<A, E1>, E0, Self>,
) -> WrapE<'a, A, Result<E1, E0>, Self>
where
Self: 'a,
{
) -> WrapE<'a, A, Result<E1, E0>, Self> {
<Self::W<Result<E1, E0>> as Monad>::bind(Self::map_err(wa, Err), |fa| match fa {
Ok(a) => Self::pure(a),
Err(e) => Self::fail(Ok(e)),
@ -348,9 +321,9 @@ pub trait MonadFailAny {
}
}
pub type WrapE<'a, A, E, Fallible> = Wrap<'a, A, <Fallible as MonadFailAny>::W<E>>;
pub type WrapE<'a, A, E, Fallible> = Wrap<'a, A, <Fallible as MonadFailAny<'a>>::W<E>>;
pub trait MonadFailAnyExt<'a>: 'a + MonadFailAny {
pub trait MonadFailAnyExt<'a>: MonadFailAny<'a> {
fn pure<E: 'a, A: 'a>(a: A) -> WrapE<'a, A, E, Self> {
<Self::W<E> as Pure>::pure(a)
}
@ -367,7 +340,7 @@ pub trait MonadFailAnyExt<'a>: 'a + MonadFailAny {
}
}
impl<'a, Fallible: ?Sized + 'a + MonadFailAny> MonadFailAnyExt<'a> for Fallible {}
impl<'a, Fallible: ?Sized + MonadFailAny<'a>> MonadFailAnyExt<'a> for Fallible {}
pub trait SharedFunctor: WeakFunctor {
type Shared<'a, A: 'a + Clone>: 'a + Clone

View File

@ -10,7 +10,7 @@ pub fn fmap<'a, T: 'a + Functor, A: 'a, B: 'a>(
}
/// Equivalent of Haskell's `fmap`. `function-function` equivalent of [Monad::bind].
pub fn bind<'a, T: 'a + Monad, A: 'a, B: 'a>(
pub fn bind<'a, T: Monad<'a>, A: 'a, B: 'a>(
f: impl 'a + FnOnce(A) -> T::F<'a, B>,
) -> impl FnOnce(T::F<'a, A>) -> T::F<'a, B> {
move |fa| T::bind(fa, f)

View File

@ -106,29 +106,19 @@ impl<U: Applicative, V: Applicative> Applicative for CompositionInstance<U, V> {
}
}
impl<U: Monad, V: Monad + LocalFunctor> Monad for CompositionInstance<U, V> {
fn bind<'a, A: 'a, B: 'a>(
impl<'a, U: Monad<'a>, V: Monad<'a> + LocalFunctor> Monad<'a> for CompositionInstance<U, V> {
fn bind<A: 'a, B: 'a>(
fa: Self::F<'a, A>,
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
) -> Self::F<'a, B>
where
Self: 'a,
{
) -> Self::F<'a, B> {
U::bind(fa, |ua| U::fmap(V::join, V::stuff::<_, U>(V::fmap(f, ua))))
}
fn iterate<'a, B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
where
Self: 'a,
{
fn iterate<B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
U::iterate(ComposedIterative(f))
}
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A>
where
Self::F<'a, A>: 'a,
Self: 'a,
{
fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
U::join(U::fmap(|ufa| U::fmap(V::join, V::stuff::<_, U>(ufa)), ffa))
}
}
@ -137,8 +127,8 @@ struct ComposedIterative<F>(F);
impl<
'a,
U: 'a + Monad,
V: 'a + Monad + LocalFunctor,
U: Monad<'a>,
V: Monad<'a> + LocalFunctor,
F: Iterative<'a, T = CompositionInstance<U, V>>,
> Iterative<'a> for ComposedIterative<F>
{
@ -157,12 +147,10 @@ impl<
}
}
impl<E, U: Monad, V: Fail<E> + LocalFunctor> Fail<E> for CompositionInstance<U, V> {
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
where
Self: 'a,
E: 'a,
impl<'a, E: 'a, U: Monad<'a>, V: Fail<'a, E> + LocalFunctor> Fail<'a, E>
for CompositionInstance<U, V>
{
fn fail<A: 'a>(e: E) -> Self::F<'a, A> {
U::pure(V::fail(e))
}
}

View File

@ -136,21 +136,15 @@ impl<E: Effect> Applicative for EffectInstance<E> {
}
}
impl<E: Effect> Monad for EffectInstance<E> {
fn bind<'a, A: 'a, B: 'a>(
impl<'a, E: 'a + Effect> Monad<'a> for EffectInstance<E> {
fn bind<A: 'a, B: 'a>(
fa: Self::F<'a, A>,
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
) -> Self::F<'a, B>
where
Self: 'a,
{
) -> Self::F<'a, B> {
f(fa.value).e_after(fa.effect)
}
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
where
Self: 'a,
{
fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
let mut effect = E::e_pure();
loop {
let fa = f.next();
@ -162,11 +156,7 @@ impl<E: Effect> Monad for EffectInstance<E> {
}
}
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A>
where
Self::F<'a, A>: 'a,
Self: 'a,
{
fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
ffa.value.e_after(ffa.effect)
}
}

View File

@ -99,18 +99,15 @@ impl Applicative for FutureInstance {
}
}
impl Monad for FutureInstance {
fn bind<'a, A: 'a, B: 'a>(
impl<'a> Monad<'a> for FutureInstance {
fn bind<A: 'a, B: 'a>(
fa: Self::F<'a, A>,
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
) -> Self::F<'a, B> {
Box::pin(async { f(fa.await).await })
}
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
where
Self: 'a,
{
fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
Box::pin(async move {
loop {
match f.next().await {
@ -121,7 +118,7 @@ impl Monad for FutureInstance {
})
}
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
Box::pin(async { ffa.await.await })
}
}

View File

@ -82,18 +82,15 @@ impl Applicative for LazyInstance {
}
}
impl Monad for LazyInstance {
fn bind<'a, A: 'a, B: 'a>(
impl<'a> Monad<'a> for LazyInstance {
fn bind<A: 'a, B: 'a>(
fa: Self::F<'a, A>,
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
) -> Self::F<'a, B> {
Box::new(|| f(fa())())
}
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
where
Self: 'a,
{
fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
loop {
match f.next()() {
ControlFlow::Continue(next_f) => f = next_f,
@ -102,7 +99,7 @@ impl Monad for LazyInstance {
}
}
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
Box::new(|| ffa()())
}
}

View File

@ -86,18 +86,15 @@ impl Applicative for OptionInstance {
}
}
impl Monad for OptionInstance {
fn bind<'a, A: 'a, B: 'a>(
impl<'a> Monad<'a> for OptionInstance {
fn bind<A: 'a, B: 'a>(
fa: Self::F<'a, A>,
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
) -> Self::F<'a, B> {
f(fa?)
}
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
where
Self: 'a,
{
fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
loop {
match f.next()? {
ControlFlow::Continue(next_f) => f = next_f,
@ -106,7 +103,7 @@ impl Monad for OptionInstance {
}
}
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
ffa?
}
}
@ -136,11 +133,8 @@ impl LocalFunctor for OptionInstance {
}
}
impl Fail<()> for OptionInstance {
fn fail<'a, A: 'a>(_e: ()) -> Self::F<'a, A>
where
Self: 'a,
{
impl<'a> Fail<'a, ()> for OptionInstance {
fn fail<A: 'a>(_e: ()) -> Self::F<'a, A> {
None
}
}

View File

@ -110,7 +110,7 @@ impl<F, O> OverloadIterative<F, O> {
}
}
impl<'a, T: 'a + Monad, O: 'a + DeriveMonad, F: Iterative<'a, T = OverloadInstance<T, O>>>
impl<'a, T: Monad<'a>, O: 'a + DeriveMonad, F: Iterative<'a, T = OverloadInstance<T, O>>>
Iterative<'a> for OverloadIterative<F, O>
{
type B = F::B;
@ -128,29 +128,19 @@ impl<'a, T: 'a + Monad, O: 'a + DeriveMonad, F: Iterative<'a, T = OverloadInstan
}
}
impl<T: Monad, O: DeriveMonad> Monad for OverloadInstance<T, O> {
fn bind<'a, A: 'a, B: 'a>(
impl<'a, T: Monad<'a>, O: 'a + DeriveMonad> Monad<'a> for OverloadInstance<T, O> {
fn bind<A: 'a, B: 'a>(
fa: Self::F<'a, A>,
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
) -> Self::F<'a, B>
where
Self: 'a,
{
) -> Self::F<'a, B> {
T::bind(fa, f)
}
fn iterate<'a, B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
where
Self: 'a,
{
fn iterate<B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
T::iterate(OverloadIterative::new(f))
}
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A>
where
Self::F<'a, A>: 'a,
Self: 'a,
{
fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
T::join(ffa)
}
}
@ -159,39 +149,29 @@ pub struct DeriveFail<Ex>(Ex);
impl<Ex> DeriveMonad for DeriveFail<Ex> {}
impl<E, Ex, T: MonadFail<Result<E, Ex>>> Fail<E> for OverloadInstance<T, DeriveFail<Ex>> {
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
where
Self: 'a,
E: 'a,
impl<'a, E: 'a, Ex: 'a, T: MonadFail<'a, Result<E, Ex>>> Fail<'a, E>
for OverloadInstance<T, DeriveFail<Ex>>
{
fn fail<A: 'a>(e: E) -> Self::F<'a, A> {
T::fail(Ok(e))
}
}
struct DeriveFailAny<Ex, Fallible>(Ex, Fallible);
impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> {
type W<E> = OverloadInstance<Fallible::W<Result<E, Ex>>, DeriveFail<Ex>>;
impl<'a, Ex: 'a, Fallible: MonadFailAny<'a>> MonadFailAny<'a> for DeriveFailAny<Ex, Fallible> {
type W<E: 'a> = OverloadInstance<Fallible::W<Result<E, Ex>>, DeriveFail<Ex>>;
type T = Fallible::W<Ex>;
fn unstuff<'a, A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T>
where
Self: 'a,
Fallible::W<Ex>: 'a,
{
fn unstuff<A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> {
Fallible::bind_err(<Self::W<E> as Functor>::fmap(Ok, wa), |err| match err {
Ok(e) => Fallible::pure(Err(e)),
Err(ex) => Fallible::fail(ex),
})
}
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self>
where
Self: 'a,
Fallible::W<Ex>: 'a,
{
fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> {
Fallible::bind(fa, |result| match result {
Ok(Ok(a)) => Fallible::pure(a),
Ok(Err(e)) => Fallible::fail(Ok(e)),
@ -199,36 +179,27 @@ impl<Ex, Fallible: MonadFailAny> MonadFailAny for DeriveFailAny<Ex, Fallible> {
})
}
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
fn map_err<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,
{
) -> WrapE<'a, A, E1, Self> {
Fallible::map_err(wa, |err| err.map(f))
}
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
fn bind_err<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,
{
) -> WrapE<'a, A, E1, Self> {
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>(
fn bind<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,
{
) -> WrapE<'a, B, E1, Self> {
Fallible::bind(wa, |result| match result {
Ok(a) => f(Ok(a)),
Err(Ok(e0)) => f(Err(e0)),

View File

@ -104,21 +104,15 @@ impl<E> Applicative for ResultInstance<E> {
}
}
impl<E> Monad for ResultInstance<E> {
fn bind<'a, A: 'a, B: 'a>(
impl<'a, E: 'a> Monad<'a> for ResultInstance<E> {
fn bind<A: 'a, B: 'a>(
fa: Self::F<'a, A>,
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
) -> Self::F<'a, B>
where
Self: 'a,
{
) -> Self::F<'a, B> {
f(fa?)
}
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
where
Self: 'a,
{
fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
loop {
match f.next()? {
ControlFlow::Continue(next_f) => f = next_f,
@ -127,10 +121,7 @@ impl<E> Monad for ResultInstance<E> {
}
}
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A>
where
Self: 'a,
{
fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
ffa?
}
}
@ -160,11 +151,8 @@ impl<E> LocalFunctor for ResultInstance<E> {
}
}
impl<E> Fail<E> for ResultInstance<E> {
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
where
Self: 'a,
{
impl<'a, E: 'a> Fail<'a, E> for ResultInstance<E> {
fn fail<A: 'a>(e: E) -> Self::F<'a, A> {
Err(e)
}
}
@ -184,61 +172,43 @@ impl<'a, A: 'a, E0: 'a> ResultExt<'a, A, E0> for Result<A, E0> {
}
}
impl MonadFailAny for ResultFailAny {
type W<E> = ResultInstance<E>;
impl<'a> MonadFailAny<'a> for ResultFailAny {
type W<E: 'a> = ResultInstance<E>;
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,
{
fn unstuff<A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> {
wa
}
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self>
where
Self: 'a,
{
fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> {
fa
}
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
fn map_err<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,
{
) -> WrapE<'a, A, E1, Self> {
wa.map_err(f)
}
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
fn bind_err<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,
{
) -> WrapE<'a, A, E1, Self> {
wa.bind_err(f)
}
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
fn bind<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,
{
) -> WrapE<'a, B, E1, Self> {
f(wa)
}
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>(
fn rotate_out<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, Result<A, E1>, E0, Self>,
) -> WrapE<'a, A, Result<E1, E0>, Self>
where
Self: 'a,
{
) -> WrapE<'a, A, Result<E1, E0>, Self> {
match wa {
Ok(Ok(a)) => Ok(a),
Ok(Err(e)) => Err(Ok(e)),
@ -247,66 +217,48 @@ impl MonadFailAny for ResultFailAny {
}
}
pub struct ResultFailOver<T: Monad>(T);
pub struct ResultFailOver<T>(T);
impl<T: Monad> MonadFailAny for ResultFailOver<T> {
type W<E> = super::composition::CompositionInstance<T, ResultInstance<E>>;
impl<'a, T: Monad<'a>> MonadFailAny<'a> for ResultFailOver<T> {
type W<E: 'a> = super::composition::CompositionInstance<T, ResultInstance<E>>;
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,
{
fn unstuff<A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> {
wa
}
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self>
where
Self: 'a,
{
fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> {
fa
}
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
fn map_err<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,
{
) -> WrapE<'a, A, E1, Self> {
T::fmap(|a| a.map_err(f), wa)
}
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
fn bind_err<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,
{
) -> WrapE<'a, A, E1, Self> {
T::bind(wa, |a| match a {
Ok(a) => T::pure(Ok(a)),
Err(e) => f(e),
})
}
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
fn bind<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,
{
) -> WrapE<'a, B, E1, Self> {
T::bind(wa, f)
}
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>(
fn rotate_out<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, Result<A, E1>, E0, Self>,
) -> WrapE<'a, A, Result<E1, E0>, Self>
where
Self: 'a,
{
) -> WrapE<'a, A, Result<E1, E0>, Self> {
T::fmap(<ResultFailAny as MonadFailAny>::rotate_out, wa)
}
}

View File

@ -74,18 +74,15 @@ impl Applicative for SoloInstance {
}
}
impl Monad for SoloInstance {
fn bind<'a, A: 'a, B: 'a>(
impl<'a> Monad<'a> for SoloInstance {
fn bind<A: 'a, B: 'a>(
fa: Self::F<'a, A>,
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
) -> Self::F<'a, B> {
f(fa)
}
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
where
Self: 'a,
{
fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
loop {
match f.next() {
ControlFlow::Continue(next_f) => f = next_f,
@ -94,7 +91,7 @@ impl Monad for SoloInstance {
}
}
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
ffa
}
}
@ -117,12 +114,8 @@ impl LocalFunctor for SoloInstance {
}
}
impl Fail<std::convert::Infallible> for SoloInstance {
fn fail<'a, A: 'a>(e: std::convert::Infallible) -> Self::F<'a, A>
where
Self: 'a,
std::convert::Infallible: 'a,
{
impl<'a> Fail<'a, std::convert::Infallible> for SoloInstance {
fn fail<A: 'a>(e: std::convert::Infallible) -> Self::F<'a, A> {
match e {}
}
}

View File

@ -215,21 +215,15 @@ impl Applicative for StacklessInstance {
}
}
impl Monad for StacklessInstance {
fn bind<'a, A: 'a, B: 'a>(
impl<'a> Monad<'a> for StacklessInstance {
fn bind<A: 'a, B: 'a>(
fa: Self::F<'a, A>,
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
) -> Self::F<'a, B>
where
Self: 'a,
{
) -> Self::F<'a, B> {
fa.bind(f)
}
fn iterate<'a, B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
where
Self: 'a,
{
fn iterate<B: 'a>(f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
Self::pure(()).bind(move |_| {
f.next().bind(|state| match state {
ControlFlow::Continue(next_f) => Self::iterate(next_f),
@ -238,11 +232,7 @@ impl Monad for StacklessInstance {
})
}
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A>
where
Self::F<'a, A>: 'a,
Self: 'a,
{
fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
Stackless(Box::new(|takesa| {
let lcell = Rc::new(Cell::new(None));
let rcell = lcell.clone();

View File

@ -117,21 +117,15 @@ impl<E> Applicative for TryFutureInstance<E> {
}
}
impl<E> Monad for TryFutureInstance<E> {
fn bind<'a, A: 'a, B: 'a>(
impl<'a, E: 'a> Monad<'a> for TryFutureInstance<E> {
fn bind<A: 'a, B: 'a>(
fa: Self::F<'a, A>,
f: impl 'a + FnOnce(A) -> Self::F<'a, B>,
) -> Self::F<'a, B>
where
Self: 'a,
{
) -> Self::F<'a, B> {
Box::pin(async { f(fa.await?).await })
}
fn iterate<'a, B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B>
where
Self: 'a,
{
fn iterate<B: 'a>(mut f: impl Iterative<'a, T = Self, B = B>) -> Self::F<'a, B> {
Box::pin(async move {
loop {
match f.next().await? {
@ -142,10 +136,7 @@ impl<E> Monad for TryFutureInstance<E> {
})
}
fn join<'a, A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A>
where
Self: 'a,
{
fn join<A: 'a>(ffa: Self::F<'a, Self::F<'a, A>>) -> Self::F<'a, A> {
Box::pin(async { ffa.await?.await })
}
}
@ -170,54 +161,38 @@ impl<E: Clone> SharedFunctor for TryFutureInstance<E> {
}
}
impl<E> Fail<E> for TryFutureInstance<E> {
fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A>
where
Self: 'a,
E: 'a,
{
impl<'a, E: 'a> Fail<'a, E> for TryFutureInstance<E> {
fn fail<A: 'a>(e: E) -> Self::F<'a, A> {
Box::pin(async { Err(e) })
}
}
pub struct FutureFailAny;
impl MonadFailAny for FutureFailAny {
type W<E> = TryFutureInstance<E>;
impl<'a> MonadFailAny<'a> for FutureFailAny {
type W<E: 'a> = TryFutureInstance<E>;
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,
{
fn unstuff<A: 'a, E: 'a>(wa: WrapE<'a, A, E, Self>) -> Wrap<'a, Result<A, E>, Self::T> {
wa
}
fn stuff<'a, A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self>
where
Self: 'a,
{
fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self> {
fa
}
fn map_err<'a, A: 'a, E0: 'a, E1: 'a>(
fn map_err<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,
{
) -> WrapE<'a, A, E1, Self> {
Box::pin(async { wa.await.map_err(f) })
}
fn bind_err<'a, A: 'a, E0: 'a, E1: 'a>(
fn bind_err<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,
{
) -> WrapE<'a, A, E1, Self> {
Box::pin(async {
match wa.await {
Ok(a) => Ok(a),
@ -226,22 +201,16 @@ impl MonadFailAny for FutureFailAny {
})
}
fn bind<'a, A: 'a, B: 'a, E0: 'a, E1: 'a>(
fn bind<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,
{
) -> WrapE<'a, B, E1, Self> {
Box::pin(async { f(wa.await).await })
}
fn rotate_out<'a, A: 'a, E0: 'a, E1: 'a>(
fn rotate_out<A: 'a, E0: 'a, E1: 'a>(
wa: WrapE<'a, Result<A, E1>, E0, Self>,
) -> WrapE<'a, A, Result<E1, E0>, Self>
where
Self: 'a,
{
) -> WrapE<'a, A, Result<E1, E0>, Self> {
Box::pin(async {
match wa.await {
Ok(Ok(a)) => Ok(a),

View File

@ -1,11 +1,11 @@
use super::*;
type Frwa<'a, A, E0, E1, Fallible> =
Wrap<'a, Result<WrapE<'a, A, E0, Fallible>, E1>, <Fallible as MonadFailAny>::T>;
Wrap<'a, Result<WrapE<'a, A, E0, Fallible>, E1>, <Fallible as MonadFailAny<'a>>::T>;
type Wwa<'a, A, E0, E1, Fallible> = WrapE<'a, WrapE<'a, A, E0, Fallible>, E1, Fallible>;
pub trait SpeculativeFail<'a>: 'a + MonadFailAny {
pub trait SpeculativeFail<'a>: MonadFailAny<'a> {
fn _speculative_a_wb<A: 'a, B: 'a, E0: 'a, E1: 'a>(
a: A,
wb: WrapE<'a, B, E0, Self>,
@ -101,4 +101,4 @@ pub trait SpeculativeFail<'a>: 'a + MonadFailAny {
}
}
impl<'a, Fallible: ?Sized + 'a + MonadFailAny> SpeculativeFail<'a> for Fallible {}
impl<'a, Fallible: ?Sized + MonadFailAny<'a>> SpeculativeFail<'a> for Fallible {}

View File

@ -55,8 +55,7 @@ pub fn applicative_follows_laws<T: Applicative + FunctorTestSuite>() -> R {
res
}
pub fn monad_follows_laws<T: Monad + FunctorTestSuite>() -> R
where {
pub fn monad_follows_laws<'a, T: Monad<'a> + FunctorTestSuite>() -> R {
let mut res = applicative_follows_laws::<T>();
T::sample(|pa| {
res += bind_respects_left_identity::<T, _, _>(|x| pa(x + 3), || 2);

View File

@ -232,7 +232,7 @@ pub fn discard_can_be_expressed_via_seq_or_la2<
)
}
pub fn bind_respects_left_identity<'a, T: 'a + Monad + Eqr, A: 'a, B: 'a + Debug + PartialEq>(
pub fn bind_respects_left_identity<'a, T: Monad<'a> + Eqr, A: 'a, B: 'a + Debug + PartialEq>(
f: impl 'a + Fn(A) -> T::F<'a, B>,
a0: impl Fn() -> A,
) -> R {
@ -243,7 +243,7 @@ pub fn bind_respects_left_identity<'a, T: 'a + Monad + Eqr, A: 'a, B: 'a + Debug
)
}
pub fn bind_respects_right_identity<'a, T: 'a + Monad + Eqr, A: 'a + Debug + PartialEq>(
pub fn bind_respects_right_identity<'a, T: Monad<'a> + Eqr, A: 'a + Debug + PartialEq>(
fa0: impl Fn() -> T::F<'a, A>,
) -> R {
T::eqr(
@ -253,7 +253,7 @@ pub fn bind_respects_right_identity<'a, T: 'a + Monad + Eqr, A: 'a + Debug + Par
)
}
pub fn bind_is_associative<'a, T: 'a + Monad + Eqr, A: 'a, B: 'a, C: 'a + Debug + PartialEq>(
pub fn bind_is_associative<'a, T: Monad<'a> + Eqr, A: 'a, B: 'a, C: 'a + Debug + PartialEq>(
f: impl 'a + Clone + Fn(B) -> T::F<'a, C>,
g: impl 'a + Clone + Fn(A) -> T::F<'a, B>,
fa0: impl 'a + Fn() -> T::F<'a, A>,
@ -267,7 +267,7 @@ pub fn bind_is_associative<'a, T: 'a + Monad + Eqr, A: 'a, B: 'a, C: 'a + Debug
pub fn seq_can_be_expressed_via_bind<
'a,
T: 'a + Monad + Eqr,
T: Monad<'a> + Eqr,
A: 'a,
B: 'a + Debug + PartialEq,
F: 'a + Fn(A) -> B,
@ -282,7 +282,7 @@ pub fn seq_can_be_expressed_via_bind<
)
}
pub fn fmap_can_be_expressed_via_bind<'a, T: 'a + Monad + Eqr, A: 'a, B: 'a + Debug + PartialEq>(
pub fn fmap_can_be_expressed_via_bind<'a, T: Monad<'a> + Eqr, A: 'a, B: 'a + Debug + PartialEq>(
f: impl 'a + Copy + Fn(A) -> B,
fa0: impl 'a + Fn() -> T::F<'a, A>,
) -> R {

View File

@ -26,39 +26,45 @@ pub use self::serialization::*;
pub use self::slice_deserializer::*;
/// Basic support for tracing events across the execution.
pub trait Diagnostic<T: Monad> {
pub trait Diagnostic<'a, T: Monad<'a>> {
/// Specify that the evaluation happens after a specific event.
fn after<'a: 'b, 'b, A>(fa: T::F<'a, A>, event: impl 'b + FnOnce() -> String) -> T::F<'a, A>;
fn after<'b, A: 'a>(fa: T::F<'a, A>, event: impl 'b + FnOnce() -> String) -> T::F<'a, A>
where
'a: 'b;
/// Specify that the evaluation happens before a specific event.
fn before<'a: 'b, 'b, A>(fa: T::F<'a, A>, event: impl 'b + FnOnce() -> String) -> T::F<'a, A>;
fn before<'b, A: 'a>(fa: T::F<'a, A>, event: impl 'b + FnOnce() -> String) -> T::F<'a, A>
where
'a: 'b;
/// Label the evaluation step as a specific named action.
fn wrapped<'a: 'b, 'b, A>(fa: T::F<'a, A>, event: impl 'b + FnOnce() -> String) -> T::F<'a, A>;
fn wrapped<'b, A: 'a>(fa: T::F<'a, A>, event: impl 'b + FnOnce() -> String) -> T::F<'a, A>
where
'a: 'b;
}
/// Execution context.
pub trait Context {
pub trait Context<'a>: 'a {
/// Type to provide for [Monad]ic representation of computation, mostly that of resolution ([`Resolution`]).
type T: Monad;
type T: Monad<'a>;
/// Type to allow improved support for result evaluation.
/// This is important for async applications stopping early.
type Fallible: MonadFailAny<T = Self::T>;
type Fallible: MonadFailAny<'a, T = Self::T>;
/// See [`Diagnostic`].
type D: Diagnostic<Self::T>;
type D: Diagnostic<'a, Self::T>;
/// Type to represent resolution errors mainly arising in [`Resolver::resolve`].
type LookupError<'a>: 'a + Error;
type LookupError: 'a + Error;
/// Get [type@Hash] of a slice, mostly for use in [`Point`].
fn hash(s: &[u8]) -> Hash;
}
/// Helper alias for [`WeakFunctor::F`] of [`Context::T`].
pub type Wrapped<'a, Ctx, A> = Wrap<'a, A, <Ctx as Context>::T>;
pub type Wrapped<'a, Ctx, A> = Wrap<'a, A, <Ctx as Context<'a>>::T>;
/// Fundamental trait for ADN objects.
pub trait Mentionable<'a, Ctx: 'a + Context>: 'a + Serializable {
pub trait Mentionable<'a, Ctx: Context<'a>>: 'a + Serializable {
/// Type of the associated factory.
type Fctr: Factory<'a, Ctx, Mtbl = Self>;
@ -83,7 +89,7 @@ pub type ParseResult<'a, Ctx, F> = Result<Mtbl<'a, Ctx, F>, <F as Factory<'a, Ct
/// Trait representing deserialisation rules for [Mentionable]s.
/// Crucial for [`crate::rstd::typeless`].
pub trait Factory<'a, Ctx: 'a + Context>: 'a + Send + Sync + Clone {
pub trait Factory<'a, Ctx: Context<'a>>: 'a + Send + Sync + Clone {
/// Type of the associated objects.
type Mtbl: Mentionable<'a, Ctx, Fctr = Self>;
/// Type of an error that [`Factory::deserialize`] can fail with.
@ -105,7 +111,7 @@ 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.
pub trait ExtFactory<'a, Ctx: 'a + Context>: Factory<'a, Ctx> {
pub trait ExtFactory<'a, Ctx: Context<'a>>: Factory<'a, Ctx> {
/// Parse the object from a slice.
fn parse_slice(
&self,

View File

@ -21,7 +21,7 @@ impl Addresses {
}
/// Read the next [Point].
pub fn next_point<'a, 'b, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
pub fn next_point<'a, 'b, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
&mut self,
deserializer: &'b mut dyn Deserializer,
resolver: Rc<dyn Resolver<'a, Ctx>>,
@ -40,7 +40,7 @@ impl Addresses {
}
}
fn _parse_slice<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
fn _parse_slice<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
factory: &A::Fctr,
slice: &[u8],
resolver: Rc<dyn Resolver<'a, Ctx>>,
@ -55,7 +55,7 @@ fn _parse_slice<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
}
}
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> ExtFactory<'a, Ctx> for F {
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> ExtFactory<'a, Ctx> for F {
fn parse_slice(
&self,
slice: &[u8],

View File

@ -1,7 +1,7 @@
use super::*;
/// Represents a potentially resolvable [`Mentionable`].
pub trait Origin<'a, Ctx: 'a + Context>: 'a {
pub trait Origin<'a, Ctx: Context<'a>>: 'a {
/// Type of the associated object.
type Mtbl: Mentionable<'a, Ctx>;
/// Value of the associated factory.

View File

@ -1,7 +1,7 @@
use super::*;
/// The main way to represent a reference in ADN.
pub struct Point<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
pub struct Point<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
/// Hash of the referred content.
/// Derived both from the serialised value ([`Serializable::serialize`])
/// and its topology ([`Mentionable::topology`]).
@ -10,7 +10,7 @@ pub struct Point<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
pub origin: Rc<dyn Origin<'a, Ctx, Mtbl = A>>,
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Clone for Point<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Clone for Point<'a, Ctx, A> {
fn clone(&self) -> Self {
Self {
point: self.point,
@ -19,7 +19,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Clone for Point<'a, Ctx, A>
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
/// See [`Origin::resolve`].
pub fn resolve(&self) -> Resolution<'a, Ctx, A> {
self.origin.clone().resolve()

View File

@ -1,10 +1,10 @@
use super::*;
pub trait TakesPoints<'a, Ctx: 'a + Context> {
pub trait TakesPoints<'a, Ctx: Context<'a>> {
fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>);
}
impl<'a, Ctx: 'a + Context> TakesPoints<'a, Ctx> for Vec<u8> {
impl<'a, Ctx: Context<'a>> TakesPoints<'a, Ctx> for Vec<u8> {
/// The only natural implementation, as used in [`Mentionable::topology`].
fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {
self.extend(point.point)

View File

@ -11,7 +11,7 @@ pub enum ResolutionError<L, P> {
/// See [`ResolutionResult`].
pub type ResolutionFailure<'a, Ctx, A> =
ResolutionError<<Ctx as Context>::LookupError<'a>, ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>;
ResolutionError<<Ctx as Context<'a>>::LookupError, ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>;
/// Result yielded by [`Origin`].
pub type ResolutionResult<'a, Ctx, A> = Result<Rc<A>, ResolutionFailure<'a, Ctx, A>>;
@ -20,7 +20,7 @@ pub type ResolutionResult<'a, Ctx, A> = Result<Rc<A>, ResolutionFailure<'a, Ctx,
pub type Resolution<'a, Ctx, A> = Wrapped<'a, Ctx, ResolutionResult<'a, Ctx, A>>;
pub type HashResolutionResult<'a, Ctx> =
Result<(Vec<u8>, Rc<dyn Resolver<'a, Ctx>>), <Ctx as Context>::LookupError<'a>>;
Result<(Vec<u8>, Rc<dyn Resolver<'a, Ctx>>), <Ctx as Context<'a>>::LookupError>;
/// Shorthand for the type of values returned by [`Resolver::resolve`].
pub type HashResolution<'a, Ctx> = Wrapped<'a, Ctx, HashResolutionResult<'a, Ctx>>;
@ -34,7 +34,7 @@ pub struct Address {
}
/// Trait representing the "rainbow table" behaviour.
pub trait Resolver<'a, Ctx: 'a + Context>: 'a {
pub trait Resolver<'a, Ctx: Context<'a>>: 'a {
/// Successfully returned value should be the inverse of the point passed
/// with topology header ([`Mentionable::topology()`]) omitted.
fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, Ctx>;

View File

@ -1,6 +1,6 @@
use super::*;
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
/// Make a [Point] from an [Address].
pub fn from_address(
address: Address,
@ -18,13 +18,13 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
}
}
struct ResolverOrigin<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> {
struct ResolverOrigin<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> {
r_factory: F,
r_address: Address,
r_resolver: Rc<dyn Resolver<'a, Ctx>>,
}
fn _resolve_origin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
fn _resolve_origin<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
origin: Rc<ResolverOrigin<'a, Ctx, A::Fctr>>,
) -> Resolution<'a, Ctx, A> {
let resolution = origin.r_resolver.clone().resolve(origin.r_address);
@ -41,7 +41,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: Context<'a>, F: Factory<'a, Ctx>> Origin<'a, Ctx> for ResolverOrigin<'a, Ctx, F> {
type Mtbl = F::Mtbl;
fn factory(&self) -> OFctr<'a, Ctx, Self> {

View File

@ -41,26 +41,18 @@ impl<S: Serializable> ExtSerializable for S {
///
/// 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: Context {
pub trait FallibleContext<'a>: Context<'a> {
/// Convert a fallible wrapped into a wrapped result.
fn unstuff<'a, A: 'a, E: 'a>(
fn unstuff<A: 'a, E: 'a>(
wa: WrapE<'a, A, E, Self::Fallible>,
) -> Wrap<'a, Result<A, E>, Self::T>
where
Self: 'a,
{
) -> Wrap<'a, Result<A, E>, Self::T> {
Self::Fallible::unstuff(wa)
}
/// Convert a wrapped result into a fallible wrapped.
fn stuff<'a, A: 'a, E: 'a>(
fa: Wrap<'a, Result<A, E>, Self::T>,
) -> WrapE<'a, A, E, Self::Fallible>
where
Self: 'a,
{
fn stuff<A: 'a, E: 'a>(fa: Wrap<'a, Result<A, E>, Self::T>) -> WrapE<'a, A, E, Self::Fallible> {
Self::Fallible::stuff(fa)
}
}
impl<Ctx: Context> FallibleContext for Ctx {}
impl<'a, Ctx: Context<'a>> FallibleContext<'a> for Ctx {}

View File

@ -35,7 +35,7 @@ impl<A: Atomic> Serializable for AtomicObject<A> {
}
}
impl<'a, Ctx: 'a + Context, A: Atomic> Mentionable<'a, Ctx> for AtomicObject<A> {
impl<'a, Ctx: Context<'a>, A: Atomic> Mentionable<'a, Ctx> for AtomicObject<A> {
type Fctr = AtomicFactory<A>;
fn factory(&self) -> Self::Fctr {
@ -66,7 +66,7 @@ impl<A: Atomic> Clone for AtomicFactory<A> {
}
}
impl<'a, Ctx: 'a + Context, A: Atomic> Factory<'a, Ctx> for AtomicFactory<A> {
impl<'a, Ctx: Context<'a>, A: Atomic> Factory<'a, Ctx> for AtomicFactory<A> {
type Mtbl = AtomicObject<A>;
type ParseError = A::AParseError;

View File

@ -9,7 +9,7 @@ use crate::rcore::*;
use super::{typeless::*, wrapped_origin::*, *};
struct CastResolver<'a, Ctx: 'a + Context> {
struct CastResolver<'a, Ctx: Context<'a>> {
points: Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>,
}
@ -61,18 +61,18 @@ impl<'a> Display for CastError<'a> {
}
impl<'a> CastError<'a> {
fn pure<Ctx: 'a + Context>(self) -> HashResolution<'a, Ctx>
fn pure<Ctx: Context<'a>>(self) -> HashResolution<'a, Ctx>
where
Ctx::LookupError<'a>: From<CastError<'a>>,
Ctx::LookupError: From<CastError<'a>>,
{
Ctx::T::pure(Err(self.into()))
}
}
impl<'a, Ctx: 'a + Context> CastResolver<'a, Ctx> {
impl<'a, Ctx: Context<'a>> CastResolver<'a, Ctx> {
fn rc(points: Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) -> Rc<dyn Resolver<'a, Ctx>>
where
Ctx::LookupError<'a>: From<CastError<'a>>,
Ctx::LookupError: From<CastError<'a>>,
{
Rc::new(Self { points })
}
@ -116,11 +116,11 @@ impl<'a, Ctx: 'a + Context> CastResolver<'a, Ctx> {
}
}
fn cast_resolved<'a, Ctx: 'a + Context>(
fn cast_resolved<'a, Ctx: Context<'a>>(
resolved: ResolutionResult<'a, Ctx, TypelessMentionable<'a, Ctx>>,
) -> HashResolutionResult<'a, Ctx>
where
Ctx::LookupError<'a>: From<CastError<'a>>,
Ctx::LookupError: From<CastError<'a>>,
{
match resolved {
Ok(mentionable) => Ok((
@ -134,9 +134,9 @@ where
}
}
impl<'a, Ctx: 'a + Context> Resolver<'a, Ctx> for CastResolver<'a, Ctx>
impl<'a, Ctx: Context<'a>> Resolver<'a, Ctx> for CastResolver<'a, Ctx>
where
Ctx::LookupError<'a>: From<CastError<'a>>,
Ctx::LookupError: From<CastError<'a>>,
{
fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, Ctx> {
let point = match self.get_point(address) {
@ -150,9 +150,9 @@ where
/// Returned by [`TypelessMentionable::cast`].
pub type CastResult<'a, Ctx, A> = Result<A, ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>;
impl<'a, Ctx: Context> TypelessMentionable<'a, Ctx>
impl<'a, Ctx: Context<'a>> TypelessMentionable<'a, Ctx>
where
Ctx::LookupError<'a>: From<CastError<'a>>,
Ctx::LookupError: From<CastError<'a>>,
{
pub fn cast_full<A: Mentionable<'a, Ctx>>(
&self,
@ -171,12 +171,12 @@ where
}
}
fn cast_resolve<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
fn cast_resolve<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
typeless_origin: Rc<dyn Origin<'a, Ctx, Mtbl = TypelessMentionable<'a, Ctx>>>,
factory: A::Fctr,
) -> Resolution<'a, Ctx, A>
where
Ctx::LookupError<'a>: From<CastError<'a>>,
Ctx::LookupError: From<CastError<'a>>,
{
Ctx::T::fmap(
move |resolved| match resolved {
@ -193,21 +193,21 @@ where
)
}
fn cast_origin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
fn cast_origin<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
typeless_origin: Rc<dyn Origin<'a, Ctx, Mtbl = TypelessMentionable<'a, Ctx>>>,
factory: A::Fctr,
) -> Rc<dyn Origin<'a, Ctx, Mtbl = A>>
where
Ctx::LookupError<'a>: From<CastError<'a>>,
Ctx::LookupError: From<CastError<'a>>,
{
wrapped_origin(factory.clone(), move || {
cast_resolve(typeless_origin.clone(), factory.clone())
})
}
impl<'a, Ctx: 'a + Context> Point<'a, Ctx, TypelessMentionable<'a, Ctx>>
impl<'a, Ctx: Context<'a>> Point<'a, Ctx, TypelessMentionable<'a, Ctx>>
where
Ctx::LookupError<'a>: From<CastError<'a>>,
Ctx::LookupError: From<CastError<'a>>,
{
fn cast_origin<A: Mentionable<'a, Ctx>>(
&self,

View File

@ -47,7 +47,7 @@ impl<ErrorA: Error, ErrorB: Error> Display for PairParseError<ErrorA, ErrorB> {
impl<ErrorA: Error, ErrorB: Error> Error for PairParseError<ErrorA, ErrorB> {}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>> StaticPair<'a, Ctx>
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>> StaticPair<'a, Ctx>
for Pair<A, B>
where
A::Fctr: InlineableFactory,

View File

@ -51,18 +51,18 @@ impl<E: Display> Display for TreeParseError<E> {
impl<E: Error> Error for TreeParseError<E> {}
pub enum RBNode<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
pub enum RBNode<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
R(RNode<'a, Ctx, A>),
B(BNode<'a, Ctx, A>),
}
pub struct BNode<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
pub struct BNode<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
cl: Nullable<'a, Ctx, RBNode<'a, Ctx, A>>,
cr: Nullable<'a, Ctx, RBNode<'a, Ctx, A>>,
key: Rc<A>,
}
pub struct RNode<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
pub struct RNode<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
cl: Nullable<'a, Ctx, BNode<'a, Ctx, A>>,
cr: Nullable<'a, Ctx, BNode<'a, Ctx, A>>,
key: Rc<A>,
@ -83,7 +83,7 @@ pub struct RFactory<F> {
key_factory: F,
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> RBNode<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> RBNode<'a, Ctx, A> {
fn key(&self) -> &A {
match self {
RBNode::R(RNode { key, .. }) => key,
@ -92,7 +92,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> RBNode<'a, Ctx, A> {
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for RBNode<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for RBNode<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) {
match self {
RBNode::R(r) => {
@ -107,7 +107,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for RBNode<'a,
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for BNode<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for BNode<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) {
self.cl.serialize(serializer);
self.cr.serialize(serializer);
@ -115,7 +115,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for BNode<'a,
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for RNode<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for RNode<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) {
self.cl.serialize(serializer);
self.cr.serialize(serializer);
@ -123,7 +123,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for RNode<'a,
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RBNode<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RBNode<'a, Ctx, A> {
type Fctr = RBFactory<A::Fctr>;
fn factory(&self) -> Self::Fctr {
@ -140,7 +140,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RB
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for BNode<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for BNode<'a, Ctx, A> {
type Fctr = BFactory<A::Fctr>;
fn factory(&self) -> Self::Fctr {
@ -156,7 +156,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for BN
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RNode<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RNode<'a, Ctx, A> {
type Fctr = RFactory<A::Fctr>;
fn factory(&self) -> Self::Fctr {
@ -172,7 +172,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for RN
}
}
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RBFactory<F> {
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RBFactory<F> {
type Mtbl = RBNode<'a, Ctx, F::Mtbl>;
type ParseError = TreeParseError<F::ParseError>;
@ -205,7 +205,7 @@ impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RBFactory<
}
}
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for BFactory<F> {
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for BFactory<F> {
type Mtbl = BNode<'a, Ctx, F::Mtbl>;
type ParseError = TreeParseError<F::ParseError>;
@ -234,7 +234,7 @@ impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for BFactory<F
}
}
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RFactory<F> {
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for RFactory<F> {
type Mtbl = RNode<'a, Ctx, F::Mtbl>;
type ParseError = TreeParseError<F::ParseError>;

View File

@ -9,13 +9,13 @@ use super::*;
pub type TPE<'a, Ctx, A> = TreeParseError<ParseError<'a, Ctx, Fctr<'a, Ctx, A>>>;
pub type TreeFaiure<'a, Ctx, A> =
ResolutionError<<Ctx as Context>::LookupError<'a>, TPE<'a, Ctx, A>>;
ResolutionError<<Ctx as Context<'a>>::LookupError, TPE<'a, Ctx, A>>;
pub type SubsetWrapped<'a, Ctx, A> = FallibleWrapped<'a, Ctx, bool, TreeFaiure<'a, Ctx, A>>;
pub type SubsetMonad<'a, Ctx, A> = FallibleMonad<Ctx, TreeFaiure<'a, Ctx, A>>;
pub type SubsetMonad<'a, Ctx, A> = FallibleMonad<'a, Ctx, TreeFaiure<'a, Ctx, A>>;
pub fn subset_pure<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
pub fn subset_pure<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
value: bool,
) -> SubsetWrapped<'a, Ctx, A> {
<SubsetMonad<'a, Ctx, A> as Pure>::pure(value)
@ -30,7 +30,7 @@ enum NodeType {
type RefData = (NodeType, Hash);
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData> for BNode<'a, Ctx, A>
{
fn split(&self) -> Split<'a, SubsetMonad<'a, Ctx, A>, A, RefData> {
@ -48,7 +48,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData> for RNode<'a, Ctx, A>
{
fn split(&self) -> Split<'a, SubsetMonad<'a, Ctx, A>, A, RefData> {
@ -66,7 +66,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
TraversibleBinaryNode<'a, SubsetMonad<'a, Ctx, A>, A, RefData> for RBNode<'a, Ctx, A>
{
fn split(&self) -> Split<'a, SubsetMonad<'a, Ctx, A>, A, RefData> {
@ -83,7 +83,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, RefData>
for Point<'a, Ctx, BNode<'a, Ctx, A>>
{
@ -105,7 +105,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, RefData>
for Point<'a, Ctx, RNode<'a, Ctx, A>>
{
@ -127,7 +127,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>
TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, RefData>
for Point<'a, Ctx, RBNode<'a, Ctx, A>>
{
@ -149,13 +149,8 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>
}
}
impl<
'a,
Ctx: 'a + Context,
A: Mentionable<'a, Ctx>,
T: Mentionable<'a, Ctx>,
D: 'a + PartialEq,
> TraversibleBinaryTree<'a, SubsetMonad<'a, Ctx, A>, A, D> for Nullable<'a, Ctx, T>
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, T: Mentionable<'a, Ctx>, D: 'a + PartialEq>
TraversibleBinaryTree<'a, SubsetMonad<'a, Ctx, A>, A, D> for Nullable<'a, Ctx, T>
where
Point<'a, Ctx, T>: TraversibleBinaryReference<'a, SubsetMonad<'a, Ctx, A>, A, D>,
{

View File

@ -4,7 +4,7 @@ use crate::rcore::*;
use crate::rstd::{inlining::*, nullable::*, point::*, *};
/// Node containing a (nullable) reference to the next node and an element.
pub struct StackNode<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
pub struct StackNode<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
/// Reference comes first due to being inlineable.
pub rest: Stack<'a, Ctx, A>,
/// Unlike the original implementation in Python, doesn't default to using Point.
@ -14,11 +14,11 @@ pub struct StackNode<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
/// Type representing a stack, an alias to a [Nullable] of a [StackNode].
pub type Stack<'a, Ctx, A> = Nullable<'a, Ctx, StackNode<'a, Ctx, A>>;
pub struct StackNodeFactory<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
pub struct StackNodeFactory<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
element_factory: A::Fctr,
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> StackNodeFactory<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> StackNodeFactory<'a, Ctx, A> {
fn new(factory: A::Fctr) -> Self {
StackNodeFactory {
element_factory: factory,
@ -26,16 +26,14 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> StackNodeFactory<'a, Ctx, A
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for StackNode<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for StackNode<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) {
self.rest.serialize(serializer);
self.element.serialize(serializer);
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx>
for StackNode<'a, Ctx, A>
{
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for StackNode<'a, Ctx, A> {
type Fctr = StackNodeFactory<'a, Ctx, A>;
fn factory(&self) -> Self::Fctr {
@ -48,7 +46,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx>
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Clone for StackNodeFactory<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Clone for StackNodeFactory<'a, Ctx, A> {
fn clone(&self) -> Self {
StackNodeFactory::new(self.element_factory.clone())
}
@ -75,7 +73,7 @@ impl<ElementParseError: Error> Display for StackParseError<ElementParseError> {
impl<ElementParseError: Error> Error for StackParseError<ElementParseError> {}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Factory<'a, Ctx>
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Factory<'a, Ctx>
for StackNodeFactory<'a, Ctx, A>
{
type Mtbl = StackNode<'a, Ctx, A>;
@ -127,7 +125,7 @@ pub type StackVecResult<'a, Ctx, A> = Result<Vec<Rc<A>>, StackFaiure<'a, Ctx, A>
pub type StackVecWrapped<'a, Ctx, A> = Wrapped<'a, Ctx, StackVecResult<'a, Ctx, A>>;
/// Extention trait with helper methods for [Stack]s.
pub trait ExtStack<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>: Mentionable<'a, Ctx> {
pub trait ExtStack<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>: Mentionable<'a, Ctx> {
/// Get an empty stack ([`Nullable::Null`]).
fn empty(factory: A::Fctr) -> Self;
/// Get the corresponding factory.
@ -140,7 +138,7 @@ pub trait ExtStack<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>: Mentionable<
fn vec(self) -> StackVecWrapped<'a, Ctx, A>;
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> ExtStack<'a, Ctx, A> for Stack<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ExtStack<'a, Ctx, A> for Stack<'a, Ctx, A> {
fn empty(factory: A::Fctr) -> Self {
Nullable::Null(StackNodeFactory::new(factory.clone()))
}
@ -176,14 +174,14 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> ExtStack<'a, Ctx, A> for St
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> InlineableFactory
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> InlineableFactory
for StackNodeFactory<'a, Ctx, A>
where
A::Fctr: InlineableFactory,
{
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> FixedSizeFactory
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> FixedSizeFactory
for StackNodeFactory<'a, Ctx, A>
where
A::Fctr: FixedSizeFactory,
@ -193,7 +191,7 @@ where
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> ConstSizeFactory
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ConstSizeFactory
for StackNodeFactory<'a, Ctx, A>
where
A::Fctr: ConstSizeFactory,
@ -226,7 +224,7 @@ mod tests {
.collect())
}
fn make_stack<Ctx: 'static + Context>() -> T<Ctx> {
fn make_stack<Ctx: Context<'static>>() -> T<Ctx> {
let stack: T<Ctx> = Stack::empty(Plain::f());
let stack: T<Ctx> = stack.add(Plain::from_slice(b"A0").into());

View File

@ -3,7 +3,7 @@
use super::*;
/// Preferred monad for fallible uses.
pub type FallibleMonad<Ctx, E> = <<Ctx as Context>::Fallible as MonadFailAny>::W<E>;
pub type FallibleMonad<'a, Ctx, E> = <<Ctx as Context<'a>>::Fallible as MonadFailAny<'a>>::W<E>;
/// Preferred [Wrapped] [Result].
pub type FallibleWrapped<'a, Ctx, A, E> = Wrap<'a, A, FallibleMonad<Ctx, E>>;
pub type FallibleWrapped<'a, Ctx, A, E> = Wrap<'a, A, FallibleMonad<'a, Ctx, E>>;

View File

@ -26,16 +26,16 @@ pub trait ConstSizeFactory: FixedSizeFactory {
}
/// Object analogue of [`InlineableFactory`].
pub trait InlineableObject<'a, Ctx: 'a + Context>: 'a {}
pub trait InlineableObject<'a, Ctx: Context<'a>>: 'a {}
/// Object analogue of [`FixedSizeFactory`].
pub trait FixedSizeObject<'a, Ctx: 'a + Context>: InlineableObject<'a, Ctx> {
pub trait FixedSizeObject<'a, Ctx: Context<'a>>: InlineableObject<'a, Ctx> {
/// For [`ConstSizeObject`] this must return [`ConstSizeObject::SIZE`].
fn size(&self) -> usize;
}
/// Object analogue of [`ConstSizeFactory`].
pub trait ConstSizeObject<'a, Ctx: 'a + Context>: FixedSizeObject<'a, Ctx> {
pub trait ConstSizeObject<'a, Ctx: Context<'a>>: FixedSizeObject<'a, Ctx> {
/// Must be equal to [`FixedSizeObject::size()`].
const SIZE: usize;
}
@ -66,12 +66,12 @@ impl<A: ConstSizeAtomic> ConstSizeFactory for AtomicFactory<A> {
const SIZE: usize = A::SIZE;
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> InlineableObject<'a, Ctx> for A where
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> InlineableObject<'a, Ctx> for A where
A::Fctr: InlineableFactory
{
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> FixedSizeObject<'a, Ctx> for A
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> FixedSizeObject<'a, Ctx> for A
where
A::Fctr: FixedSizeFactory,
{
@ -80,7 +80,7 @@ where
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> ConstSizeObject<'a, Ctx> for A
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> ConstSizeObject<'a, Ctx> for A
where
A::Fctr: ConstSizeFactory,
{
@ -134,7 +134,7 @@ pub type CheckedParseResult<'a, Ctx, F> =
Result<Mtbl<'a, Ctx, F>, CheckedParseError<ParseError<'a, Ctx, F>>>;
/// 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: Context<'a>>: FixedSizeFactory + Factory<'a, Ctx> {
/// Verify proper read length using [`Deserializer::tell`].
fn deserialize_checked(
&self,
@ -145,12 +145,12 @@ pub trait CheckedParse<'a, Ctx: 'a + Context>: FixedSizeFactory + Factory<'a, Ct
}
/// Extension trait for factories that ensures fixed size write.
pub trait CheckedSerialize<'a, Ctx: 'a + Context>: Serializable + FixedSizeObject<'a, Ctx> {
pub trait CheckedSerialize<'a, Ctx: Context<'a>>: Serializable + FixedSizeObject<'a, Ctx> {
/// Verify proper write length using [`Serializer::tell`].
fn serialize_checked(&self, serializer: &mut dyn Serializer) -> Result<(), SizeError>;
}
impl<'a, Ctx: 'a + Context, F: FixedSizeFactory + Factory<'a, Ctx>> CheckedParse<'a, Ctx> for F {
impl<'a, Ctx: Context<'a>, F: FixedSizeFactory + Factory<'a, Ctx>> CheckedParse<'a, Ctx> for F {
fn deserialize_checked(
&self,
deserializer: &mut dyn Deserializer,
@ -173,7 +173,7 @@ impl<'a, Ctx: 'a + Context, F: FixedSizeFactory + Factory<'a, Ctx>> CheckedParse
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx> + FixedSizeObject<'a, Ctx>>
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx> + FixedSizeObject<'a, Ctx>>
CheckedSerialize<'a, Ctx> for A
{
fn serialize_checked(&self, serializer: &mut dyn Serializer) -> Result<(), SizeError> {

View File

@ -27,7 +27,7 @@ pub trait StaticPairSerializable {
/// at the cost of having to specify two extra fields.
///
/// Note: [`StaticPair::FA`] requires [`InlineableFactory`] be implemented.
pub trait StaticPair<'a, Ctx: 'a + Context>:
pub trait StaticPair<'a, Ctx: Context<'a>>:
'a + StaticPairSerializable<SA = Self::A, SB = Self::B>
{
/// [Factory] data. May, depending on the usecase, include factory (factories) on the element(s).
@ -87,7 +87,7 @@ impl<SP> Deref for StaticPairObject<SP> {
}
/// Generic implementation of a [Factory] for [StaticPair]s.
pub struct StaticPairFactory<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> {
pub struct StaticPairFactory<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> {
factory_data: SP::FactoryData,
}
@ -99,7 +99,7 @@ impl<SP: StaticPairSerializable> Serializable for StaticPairObject<SP> {
}
}
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Mentionable<'a, Ctx> for StaticPairObject<SP> {
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> Mentionable<'a, Ctx> for StaticPairObject<SP> {
type Fctr = StaticPairFactory<'a, Ctx, SP>;
fn factory(&self) -> Self::Fctr {
@ -115,7 +115,7 @@ impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Mentionable<'a, Ctx> for St
}
}
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Clone for StaticPairFactory<'a, Ctx, SP> {
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> Clone for StaticPairFactory<'a, Ctx, SP> {
fn clone(&self) -> Self {
Self {
factory_data: self.factory_data.clone(),
@ -123,7 +123,7 @@ impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Clone for StaticPairFactory
}
}
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Factory<'a, Ctx>
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> Factory<'a, Ctx>
for StaticPairFactory<'a, Ctx, SP>
{
type Mtbl = StaticPairObject<SP>;
@ -156,14 +156,14 @@ impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> Factory<'a, Ctx>
}
}
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> InlineableFactory
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> InlineableFactory
for StaticPairFactory<'a, Ctx, SP>
where
SP::FB: InlineableFactory,
{
}
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> FixedSizeFactory
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> FixedSizeFactory
for StaticPairFactory<'a, Ctx, SP>
where
SP::FA: FixedSizeFactory,
@ -175,7 +175,7 @@ where
}
}
impl<'a, Ctx: 'a + Context, SP: StaticPair<'a, Ctx>> ConstSizeFactory
impl<'a, Ctx: Context<'a>, SP: StaticPair<'a, Ctx>> ConstSizeFactory
for StaticPairFactory<'a, Ctx, SP>
where
SP::FA: ConstSizeFactory,

View File

@ -4,7 +4,7 @@ use crate::rcore::*;
use super::*;
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
fn prepare_bytes_for_hashing(mentioned: &A) -> Vec<u8> {
let mut vec = mentioned.topology().to_vec();
mentioned.serialize(&mut vec);
@ -29,7 +29,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
struct LocalOrigin<A>(Rc<A>);
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for LocalOrigin<A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for LocalOrigin<A> {
type Mtbl = A;
fn factory(&self) -> A::Fctr {
@ -47,13 +47,13 @@ impl<A> From<Rc<A>> for LocalOrigin<A> {
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> From<Rc<A>> for Point<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> From<Rc<A>> for Point<'a, Ctx, A> {
fn from(value: Rc<A>) -> Self {
Self::from_mentionable(value)
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> From<A> for Point<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> From<A> for Point<'a, Ctx, A> {
fn from(value: A) -> Self {
Self::from_mentionable(value.into())
}

View File

@ -5,7 +5,7 @@ use crate::rcore::*;
use super::{inlining::*, point::*, *};
/// Nullable reference type. Made for use as a linking element in data structures.
pub enum Nullable<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
pub enum Nullable<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
/// Unlike original Python implementation, stores the factory only in the null case.
Null(A::Fctr),
NotNull(Point<'a, Ctx, A>),
@ -18,7 +18,7 @@ pub struct NullableFactory<F> {
factory: F,
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for Nullable<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for Nullable<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) {
serializer.write(match self {
Nullable::Null(_) => &HASH_ZEROS,
@ -27,7 +27,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for Nullable<'
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nullable<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nullable<'a, Ctx, A> {
type Fctr = NullableFactory<A::Fctr>;
fn factory(&self) -> Self::Fctr {
@ -49,7 +49,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Nu
}
}
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for NullableFactory<F> {
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for NullableFactory<F> {
type Mtbl = Nullable<'a, Ctx, F::Mtbl>;
type ParseError = PointParseError;
@ -74,7 +74,7 @@ impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for NullableFa
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, Nullable<'a, Ctx, A>> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, Nullable<'a, Ctx, A>> {
/// Reduce [Nullable] nesting.
pub fn join(&self) -> Resolution<'a, Ctx, Nullable<'a, Ctx, A>> {
match self {
@ -87,7 +87,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, Nullable<
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Nullable<'a, Ctx, A> {
fn from_mentionable(mentionable: Rc<A>) -> Self {
Self::NotNull(mentionable.into())
}
@ -99,7 +99,7 @@ impl<F> NullableFactory<F> {
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Clone for Nullable<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Clone for Nullable<'a, Ctx, A> {
fn clone(&self) -> Self {
match self {
Self::Null(factory) => Self::Null(factory.clone()),
@ -112,13 +112,13 @@ impl<F> AlwaysConstSize for NullableFactory<F> {
const _SIZE: usize = HASH_SIZE;
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> From<Rc<A>> for Nullable<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> From<Rc<A>> for Nullable<'a, Ctx, A> {
fn from(value: Rc<A>) -> Self {
Self::from_mentionable(value)
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> From<A> for Nullable<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> From<A> for Nullable<'a, Ctx, A> {
fn from(value: A) -> Self {
Self::from_mentionable(value.into())
}

View File

@ -4,13 +4,13 @@ use std::{error::Error, fmt::Display, rc::Rc};
use crate::rcore::*;
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Serializable for Point<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Serializable for Point<'a, Ctx, A> {
fn serialize(&self, serializer: &mut dyn Serializer) {
serializer.write(&self.point)
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Point<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Point<'a, Ctx, A> {
type Fctr = PointFactory<A::Fctr>;
fn factory(&self) -> Self::Fctr {
@ -57,13 +57,13 @@ impl From<&[u8]> for PointParseError {
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> AsRef<[u8]> for Point<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> AsRef<[u8]> for Point<'a, Ctx, A> {
fn as_ref(&self) -> &[u8] {
&self.point
}
}
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Factory<'a, Ctx> for PointFactory<F> {
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Factory<'a, Ctx> for PointFactory<F> {
type Mtbl = Point<'a, Ctx, F::Mtbl>;
type ParseError = PointParseError;

View File

@ -86,16 +86,25 @@ impl<A> Traced<A> {
}
}
impl Diagnostic<TracedInstance> for TracedDiagnostic {
fn after<'a: 'b, 'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A> {
impl<'a> Diagnostic<'a, TracedInstance> for TracedDiagnostic {
fn after<'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A>
where
'a: 'b,
{
fa.after(TraceBox::event(event()))
}
fn before<'a: 'b, 'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A> {
fn before<'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A>
where
'a: 'b,
{
fa.before(TraceBox::event(event()))
}
fn wrapped<'a: 'b, 'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A> {
fn wrapped<'b, A>(fa: Traced<A>, event: impl FnOnce() -> String) -> Traced<A>
where
'a: 'b,
{
fa.wrapped(event())
}
}

View File

@ -2,17 +2,17 @@ use crate::rstd::{cast::*, typeless::*};
use super::*;
struct TracedResolver<'a, Ctx: 'a + Context> {
struct TracedResolver<'a, Ctx: Context<'a>> {
resolver: Rc<dyn Resolver<'a, Ctx>>,
}
impl<'a, Ctx: 'a + Context<T = TracedInstance>> TracedResolver<'a, Ctx> {
impl<'a, Ctx: Context<'a, T = TracedInstance>> TracedResolver<'a, Ctx> {
fn wrap(resolver: Rc<dyn Resolver<'a, Ctx>>) -> Rc<dyn Resolver<'a, Ctx>> {
Rc::new(Self { resolver })
}
}
impl<'a, Ctx: 'a + Context<T = TracedInstance>> Resolver<'a, Ctx> for TracedResolver<'a, Ctx> {
impl<'a, Ctx: Context<'a, T = TracedInstance>> Resolver<'a, Ctx> for TracedResolver<'a, Ctx> {
fn resolve(self: Rc<Self>, address: Address) -> HashResolution<'a, Ctx> {
TracedInstance::fmap(
|resolved| {
@ -27,7 +27,7 @@ impl<'a, Ctx: 'a + Context<T = TracedInstance>> Resolver<'a, Ctx> for TracedReso
}
/// Extension trait to trace the evaluation flow.
pub trait Traceable<'a, Ctx: 'a + Context<T = TracedInstance>>:
pub trait Traceable<'a, Ctx: Context<'a, T = TracedInstance>>:
Mentionable<'a, Ctx> + Sized
{
/// Re-cast the value, adding an extra[^extra]
@ -38,9 +38,9 @@ pub trait Traceable<'a, Ctx: 'a + Context<T = TracedInstance>>:
fn trace(self: Rc<Self>) -> CastResult<'a, Ctx, Self>;
}
impl<'a, Ctx: 'a + Context<T = TracedInstance>, A: Mentionable<'a, Ctx>> Traceable<'a, Ctx> for A
impl<'a, Ctx: Context<'a, T = TracedInstance>, A: Mentionable<'a, Ctx>> Traceable<'a, Ctx> for A
where
Ctx::LookupError<'a>: From<CastError<'a>>,
Ctx::LookupError: From<CastError<'a>>,
{
fn trace(self: Rc<Self>) -> CastResult<'a, Ctx, Self> {
let factory = self.factory();

View File

@ -5,7 +5,7 @@ use super::{wrapped_origin::*, *};
type TypelessSerialize<'a> = dyn 'a + Fn(&mut dyn Serializer);
/// See [`Point::typeless`].
pub struct TypelessMentionable<'a, Ctx: 'a + Context> {
pub struct TypelessMentionable<'a, Ctx: Context<'a>> {
t_serialize: Box<TypelessSerialize<'a>>,
t_factory: TypelessFactory<'a, Ctx>,
t_topology: Hash,
@ -14,7 +14,7 @@ pub struct TypelessMentionable<'a, Ctx: 'a + Context> {
type TypelessParsed<'a, Ctx> = Result<TypelessMentionable<'a, Ctx>, Box<dyn 'a + Error>>;
trait Tde<'a, Ctx: 'a + Context>: 'a + Send + Sync {
trait Tde<'a, Ctx: Context<'a>>: 'a + Send + Sync {
fn clone_box(&self) -> TdeBox<'a, Ctx>;
fn de(
@ -27,7 +27,7 @@ trait Tde<'a, Ctx: 'a + Context>: 'a + Send + Sync {
type TdeBox<'a, Ctx> = Box<dyn Tde<'a, Ctx>>;
trait Tut<'a, Ctx: 'a + Context>: 'a + Send + Sync {
trait Tut<'a, Ctx: Context<'a>>: 'a + Send + Sync {
fn clone_box(&self) -> TutBox<'a, Ctx>;
fn ut(&self, tail: &[u8]) -> TypelessError<'a>;
@ -36,18 +36,18 @@ trait Tut<'a, Ctx: 'a + Context>: 'a + Send + Sync {
type TutBox<'a, Ctx> = Box<dyn Tut<'a, Ctx>>;
/// See [`Point::typeless`]/[`TypelessMentionable`].
pub struct TypelessFactory<'a, Ctx: 'a + Context> {
pub struct TypelessFactory<'a, Ctx: Context<'a>> {
t_deserialize: TdeBox<'a, Ctx>,
t_unexpected_tail: TutBox<'a, Ctx>,
}
impl<'a, Ctx: 'a + Context> Serializable for TypelessMentionable<'a, Ctx> {
impl<'a, Ctx: Context<'a>> Serializable for TypelessMentionable<'a, Ctx> {
fn serialize(&self, serializer: &mut dyn Serializer) {
(self.t_serialize)(serializer);
}
}
impl<'a, Ctx: 'a + Context> Mentionable<'a, Ctx> for TypelessMentionable<'a, Ctx> {
impl<'a, Ctx: Context<'a>> Mentionable<'a, Ctx> for TypelessMentionable<'a, Ctx> {
type Fctr = TypelessFactory<'a, Ctx>;
fn factory(&self) -> Self::Fctr {
@ -65,7 +65,7 @@ impl<'a, Ctx: 'a + Context> Mentionable<'a, Ctx> for TypelessMentionable<'a, Ctx
}
}
impl<'a, Ctx: 'a + Context> Clone for TypelessFactory<'a, Ctx> {
impl<'a, Ctx: Context<'a>> Clone for TypelessFactory<'a, Ctx> {
fn clone(&self) -> Self {
Self {
t_deserialize: self.t_deserialize.clone_box(),
@ -86,7 +86,7 @@ impl<'a> Display for TypelessError<'a> {
impl<'a> Error for TypelessError<'a> {}
impl<'a, Ctx: 'a + Context> Factory<'a, Ctx> for TypelessFactory<'a, Ctx> {
impl<'a, Ctx: Context<'a>> Factory<'a, Ctx> for TypelessFactory<'a, Ctx> {
type Mtbl = TypelessMentionable<'a, Ctx>;
type ParseError = TypelessError<'a>;
@ -108,7 +108,7 @@ impl<'a, Ctx: 'a + Context> Factory<'a, Ctx> for TypelessFactory<'a, Ctx> {
}
}
impl<'a, Ctx: 'a + Context> TypelessMentionable<'a, Ctx> {
impl<'a, Ctx: Context<'a>> TypelessMentionable<'a, Ctx> {
pub fn from_typed<A: Mentionable<'a, Ctx>>(mentionable: Rc<A>) -> Self {
let factory = TypelessFactory::from_typed(mentionable.factory());
let topology = mentionable.topology();
@ -122,7 +122,7 @@ impl<'a, Ctx: 'a + Context> TypelessMentionable<'a, Ctx> {
}
}
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Tde<'a, Ctx> for F {
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Tde<'a, Ctx> for F {
fn clone_box(&self) -> TdeBox<'a, Ctx> {
Box::new(self.clone())
}
@ -143,7 +143,7 @@ impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Tde<'a, Ctx> for F {
}
}
impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Tut<'a, Ctx> for F {
impl<'a, Ctx: Context<'a>, F: Factory<'a, Ctx>> Tut<'a, Ctx> for F {
fn clone_box(&self) -> TutBox<'a, Ctx> {
Box::new(self.clone())
}
@ -153,7 +153,7 @@ impl<'a, Ctx: 'a + Context, F: Factory<'a, Ctx>> Tut<'a, Ctx> for F {
}
}
impl<'a, Ctx: 'a + Context> TypelessFactory<'a, Ctx> {
impl<'a, Ctx: Context<'a>> TypelessFactory<'a, Ctx> {
pub fn from_typed<F: Factory<'a, Ctx>>(factory: F) -> Self {
TypelessFactory {
t_deserialize: Box::new(factory.clone()),
@ -168,7 +168,7 @@ impl<'a> TypelessError<'a> {
}
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
/// Typeless version of the point.
pub fn typeless(&self) -> Point<'a, Ctx, TypelessMentionable<'a, Ctx>> {
Point {
@ -182,14 +182,14 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> {
}
}
pub trait MentionableExt<'a, Ctx: 'a + Context>: Mentionable<'a, Ctx> {
pub trait MentionableExt<'a, Ctx: Context<'a>>: Mentionable<'a, Ctx> {
/// References ([Point]s) to other objects. Typeless.
fn points_typeless(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>);
/// [Vec] of [Point]s as used by [`Mentionable::topology`].
fn points_vec(&self) -> Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>;
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> MentionableExt<'a, Ctx> for A {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> MentionableExt<'a, Ctx> for A {
fn points_typeless(&self, points: &mut Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>) {
self.points_typed(points)
}
@ -201,7 +201,7 @@ impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> MentionableExt<'a, Ctx> for
}
}
impl<'a, Ctx: 'a + Context> TakesPoints<'a, Ctx>
impl<'a, Ctx: Context<'a>> TakesPoints<'a, Ctx>
for Vec<Point<'a, Ctx, TypelessMentionable<'a, Ctx>>>
{
fn take<A: Mentionable<'a, Ctx>>(&mut self, point: &Point<'a, Ctx, A>) {

View File

@ -1,6 +1,6 @@
use super::*;
pub fn wrapped_origin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
pub fn wrapped_origin<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>>(
factory: A::Fctr,
resolve: impl 'a + Fn() -> Resolution<'a, Ctx, A>,
) -> Rc<dyn Origin<'a, Ctx, Mtbl = A>> {
@ -10,7 +10,7 @@ pub fn wrapped_origin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>>(
})
}
pub trait MappableOrigin<'a, Ctx: 'a + Context>: Origin<'a, Ctx> {
pub trait MappableOrigin<'a, Ctx: Context<'a>>: Origin<'a, Ctx> {
fn map<B: Mentionable<'a, Ctx>>(
self: Rc<Self>,
map_ok: impl 'a + Send + Sync + Clone + Fn(Rc<Self::Mtbl>) -> B,
@ -35,9 +35,9 @@ pub trait MappableOrigin<'a, Ctx: 'a + Context>: Origin<'a, Ctx> {
}
}
impl<'a, Ctx: 'a + Context, O: ?Sized + Origin<'a, Ctx>> MappableOrigin<'a, Ctx> for O {}
impl<'a, Ctx: Context<'a>, 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: Context<'a>, A: Mentionable<'a, Ctx>, B: Mentionable<'a, Ctx>>(
resolve: impl 'a + Fn() -> Resolution<'a, Ctx, A>,
map_ok: impl 'a + Fn(Rc<A>) -> B,
map_err: impl 'a + Fn(ParseError<'a, Ctx, A::Fctr>) -> ParseError<'a, Ctx, B::Fctr>,
@ -56,12 +56,12 @@ fn map_resolve<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>, B: Mentionable<'a
)
}
struct WrappedOrigin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> {
struct WrappedOrigin<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> {
w_factory: A::Fctr,
w_resolve: Box<dyn 'a + Fn() -> Resolution<'a, Ctx, A>>,
}
impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for WrappedOrigin<'a, Ctx, A> {
impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Origin<'a, Ctx> for WrappedOrigin<'a, Ctx, A> {
type Mtbl = A;
fn factory(&self) -> Fctr<'a, Ctx, Self::Mtbl> {

View File

@ -12,16 +12,16 @@ use crate::rstd::typeless::*;
pub struct NoDiagnostic;
impl<T: Monad> Diagnostic<T> for NoDiagnostic {
fn after<'a: 'b, 'b, A>(fa: T::F<'a, A>, _event: impl FnOnce() -> String) -> T::F<'a, A> {
impl<'a, T: Monad<'a>> Diagnostic<'a, T> for NoDiagnostic {
fn after<'b, A>(fa: T::F<'a, A>, _event: impl 'b + FnOnce() -> String) -> T::F<'a, A> {
fa
}
fn before<'a: 'b, 'b, A>(fa: T::F<'a, A>, _event: impl FnOnce() -> String) -> T::F<'a, A> {
fn before<'b, A>(fa: T::F<'a, A>, _event: impl 'b + FnOnce() -> String) -> T::F<'a, A> {
fa
}
fn wrapped<'a: 'b, 'b, A>(fa: T::F<'a, A>, _event: impl FnOnce() -> String) -> T::F<'a, A> {
fn wrapped<'b, A>(fa: T::F<'a, A>, _event: impl 'b + FnOnce() -> String) -> T::F<'a, A> {
fa
}
}
@ -66,14 +66,14 @@ impl<'a> Display for TestLookupError<'a> {
impl<'a> Error for TestLookupError<'a> {}
impl Context for TestContextPlain {
impl<'a> Context<'a> for TestContextPlain {
type T = instances::solo::SoloInstance;
type Fallible = instances::result::ResultFailAny;
type D = NoDiagnostic;
type LookupError<'a> = TestLookupError<'a>;
type LookupError = TestLookupError<'a>;
fn hash(s: &[u8]) -> Hash {
let mut hasher = Sha256::new();

View File

@ -8,14 +8,14 @@ use super::*;
pub struct TestContextCounted;
impl Context for TestContextCounted {
impl<'a> Context<'a> for TestContextCounted {
type T = CountedInstance;
type Fallible = instances::result::ResultFailOver<Self::T>;
type D = NoDiagnostic;
type LookupError<'a> = TestLookupError<'a>;
type LookupError = TestLookupError<'a>;
fn hash(s: &[u8]) -> Hash {
TestContextPlain::hash(s)

View File

@ -5,14 +5,14 @@ use super::*;
pub struct TestContextTraced;
impl Context for TestContextTraced {
impl<'a> Context<'a> for TestContextTraced {
type T = TracedInstance;
type Fallible = instances::result::ResultFailOver<Self::T>;
type D = TracedDiagnostic;
type LookupError<'a> = TestLookupError<'a>;
type LookupError = TestLookupError<'a>;
fn hash(s: &[u8]) -> Hash {
TestContextPlain::hash(s)