Diffstat (limited to 'src/effect.rs')
| -rw-r--r-- | src/effect.rs | 137 |
1 files changed, 71 insertions, 66 deletions
diff --git a/src/effect.rs b/src/effect.rs index 0c85769..87cee7e 100644 --- a/src/effect.rs +++ b/src/effect.rs @@ -38,81 +38,99 @@ use crate::{higher_ranked_trait, higher_ranked_type}; // || B // )) -pub trait Effect: - Join<Effect = Self> + TryJoin<Effect = Self> + Send + Sync + Sized + 'static -{ - type Erased<T: Send + Sync>: ErasedHrt<T, Self>; +pub trait Ss: Send + Sync {} + +impl<T: Send + Sync> Ss for T {} + +pub trait Effect: Join<Effect = Self> + TryJoin<Effect = Self> + Ss + Sized + 'static { + type Erased<T: Ss>: ErasedHrt<T, Self>; - type Ready<'a, T: Send + Sync + 'a>: Effective<'a, Output = T, Effect = Self>; + type Ready<'a, T: Ss + 'a>: Effective<'a, Output = T, Effect = Self>; - fn ready<'a, T: Send + Sync + 'a>(value: T) -> Self::Ready<'a, T>; + fn ready<'a, T: Ss + 'a>(value: T) -> Self::Ready<'a, T>; - type FromFuture<'a, F: Send + Sync + 'a>: Effective<'a, Output = F::Output, Effect = Self> + type FromFuture<'a, F: Ss + 'a>: Effective<'a, Output = F::Output, Effect = Self> where F: Future, - F::Output: Send + Sync + 'a; + F::Output: Ss + 'a; - fn from_future<'a, F: Send + Sync + 'a>(future: F) -> Self::FromFuture<'a, F> + fn from_future<'a, F: Ss + 'a>(future: F) -> Self::FromFuture<'a, F> where F: Future, - F::Output: Send + Sync + 'a; + F::Output: Ss + 'a; } -pub trait ErasedForLt<'a, T: Send + Sync + 'a, E: Effect, Bound: 'a, O: 'a> { +pub trait ErasedForLt<'a, T: Ss + 'a, E: Effect, Bound: 'a, O: 'a> { type T: Effective<'a, Output = T, Effect = E>; } -pub trait ErasedHrt<T: Send + Sync, E: Effect> { +pub trait ErasedHrt<T: Ss, E: Effect> { type T<B>: for<'a> ErasedForLt<'a, T, E, &'a (T, B), B>; } pub type ErasedEffective<'lt, Output, E, B = ()> = - <<<E as Effect>::Erased<Output> as ErasedHrt<Output, E>>::T<B> as ErasedForLt<'lt, Output, E, &'lt (Output, B), B>>::T; - -pub trait Effective<'lt>: Send + Sync + 'lt { + <<<E as Effect>::Erased<Output> as ErasedHrt<Output, E>>::T<B> as ErasedForLt< + 'lt, + Output, + E, + &'lt (Output, B), + B, + >>::T; + +pub trait Effective<'lt>: Ss + 'lt { fn into_erased<B>(self) -> ErasedEffective<'lt, Self::Output, Self::Effect, B>; /// The effect the effective belongs to. type Effect: Effect; /// The type of the effective's output value. - type Output: Send + Sync + 'lt; + type Output: Ss + 'lt; /// Future that resolves to the same value as the effective. - type IntoFuture: Send + Sync + Future<Output = Self::Output>; + type IntoFuture: Ss + Future<Output = Self::Output>; /// Convert the effective into a general future for use in async. fn into_future(self) -> Self::IntoFuture; - type Loop<'ctx: 'a, 'a, T: Send + Sync + 'a, F: Send + Sync + 'a>: Effective< + type Loop<'ctx: 'a, 'a, T: Ss + 'a, F: Ss + 'a>: Effective< 'a, Output = (Self::Output, T), Effect = Self::Effect, > where - F: for<'b> FnMut(&'b mut Self::Output) -> ErasedEffective<'b, ControlFlow<T>, Self::Effect, (&'b mut Self::Output, &'ctx ())>, + F: for<'b> FnMut( + &'b mut Self::Output, + ) -> ErasedEffective< + 'b, + ControlFlow<T>, + Self::Effect, + (&'b mut Self::Output, &'ctx ()), + >, 'lt: 'a; - fn r#loop<'ctx: 'a, 'a, T: Send + Sync + 'a, F: Send + Sync + 'a>(self, cb: F) -> Self::Loop<'ctx, 'a, T, F> + fn r#loop<'ctx: 'a, 'a, T: Ss + 'a, F: Ss + 'a>(self, cb: F) -> Self::Loop<'ctx, 'a, T, F> where - F: for<'b> FnMut(&'b mut Self::Output) -> ErasedEffective<'b, ControlFlow<T>, Self::Effect, (&'b mut Self::Output, &'ctx ())>, + F: for<'b> FnMut( + &'b mut Self::Output, + ) -> ErasedEffective< + 'b, + ControlFlow<T>, + Self::Effect, + (&'b mut Self::Output, &'ctx ()), + >, 'lt: 'a; - type Map<'a, T: Send + Sync + 'a, F: Send + Sync + 'a>: Effective< - 'a, - Output = T, - Effect = Self::Effect, - > + type Map<'a, T: Ss + 'a, F: Ss + 'a>: Effective<'a, Output = T, Effect = Self::Effect> where F: FnOnce(Self::Output) -> T, 'lt: 'a; - fn map<'a, T: Send + Sync + 'a, F: Send + Sync + 'a>(self, cb: F) -> Self::Map<'a, T, F> + fn map<'a, T: Ss + 'a, F: Ss + 'a>(self, cb: F) -> Self::Map<'a, T, F> where F: FnOnce(Self::Output) -> T, 'lt: 'a; - type Then<'a, T: Send + Sync + 'a, V: Send + Sync + 'a, F: Send + Sync + 'a>: Effective< + type Then<'a, T: Ss + 'a, V: Ss + 'a, F: Ss + 'a>: Effective< 'a, Output = T, Effect = Self::Effect, @@ -122,40 +140,43 @@ pub trait Effective<'lt>: Send + Sync + 'lt { V: Effective<'a, Output = T, Effect = Self::Effect>, 'lt: 'a; - fn then<'a, T: Send + Sync + 'a, V: Send + Sync + 'a, F: Send + Sync + 'a>( - self, - cb: F, - ) -> Self::Then<'a, T, V, F> + fn then<'a, T: Ss + 'a, V: Ss + 'a, F: Ss + 'a>(self, cb: F) -> Self::Then<'a, T, V, F> where F: FnOnce(Self::Output) -> V, V: Effective<'a, Output = T, Effect = Self::Effect>, 'lt: 'a; - type AsCtx<'ctx: 'a, 'a, T: Send + Sync + 'a, F: Send + Sync + 'a>: Effective< + type AsCtx<'ctx: 'a, 'a, T: Ss + 'a, F: Ss + 'a>: Effective< 'a, Output = (Self::Output, T), Effect = Self::Effect, > where - F: for<'b> FnOnce(&'b mut Self::Output) -> ErasedEffective<'b, T, Self::Effect, (&'b mut Self::Output, &'ctx ())>, + F: for<'b> FnOnce( + &'b mut Self::Output, + ) + -> ErasedEffective<'b, T, Self::Effect, (&'b mut Self::Output, &'ctx ())>, 'lt: 'a; - fn as_ctx<'ctx: 'a, 'a, T: Send + Sync + 'a, F: Send + Sync + 'a>(self, cb: F) -> Self::AsCtx<'ctx, 'a, T, F> + fn as_ctx<'ctx: 'a, 'a, T: Ss + 'a, F: Ss + 'a>(self, cb: F) -> Self::AsCtx<'ctx, 'a, T, F> where - F: for<'b> FnOnce(&'b mut Self::Output) -> ErasedEffective<'b, T, Self::Effect, (&'b mut Self::Output, &'ctx ())>, + F: for<'b> FnOnce( + &'b mut Self::Output, + ) + -> ErasedEffective<'b, T, Self::Effect, (&'b mut Self::Output, &'ctx ())>, 'lt: 'a; } pub trait TryEffective<'lt>: Effective<'lt, Output = Result<Self::Ok, Self::Err>> { - type Ok: Send + Sync + 'lt; - type Err: Send + Sync + 'lt; + type Ok: Ss + 'lt; + type Err: Ss + 'lt; } impl<'lt, T, Ok, Err> TryEffective<'lt> for T where T: Effective<'lt, Output = Result<Ok, Err>>, - Ok: Send + Sync + 'lt, - Err: Send + Sync + 'lt, + Ok: Ss + 'lt, + Err: Ss + 'lt, { type Ok = Ok; @@ -165,7 +186,7 @@ where pub trait Join { type Effect: Effect; - type Two<'a, T0: Send + Sync + 'a, T1: Send + Sync + 'a>: Effective< + type Two<'a, T0: Ss + 'a, T1: Ss + 'a>: Effective< 'a, Output = (T0::Output, T1::Output), Effect = Self::Effect, @@ -174,7 +195,7 @@ pub trait Join { T0: Effective<'a, Effect = Self::Effect>, T1: Effective<'a, Effect = Self::Effect>; - type Three<'a, T0: Send + Sync + 'a, T1: Send + Sync + 'a, T2: Send + Sync + 'a>: Effective< + type Three<'a, T0: Ss + 'a, T1: Ss + 'a, T2: Ss + 'a>: Effective< 'a, Output = (T0::Output, T1::Output, T2::Output), Effect = Self::Effect, @@ -184,14 +205,12 @@ pub trait Join { T1: Effective<'a, Effect = Self::Effect>, T2: Effective<'a, Effect = Self::Effect>; - fn two<'a, T0: Send + Sync + 'a, T1: Send + Sync + 'a>( - effectives: (T0, T1), - ) -> Self::Two<'a, T0, T1> + fn two<'a, T0: Ss + 'a, T1: Ss + 'a>(effectives: (T0, T1)) -> Self::Two<'a, T0, T1> where T0: Effective<'a, Effect = Self::Effect>, T1: Effective<'a, Effect = Self::Effect>; - fn three<'a, T0: Send + Sync + 'a, T1: Send + Sync + 'a, T2: Send + Sync + 'a>( + fn three<'a, T0: Ss + 'a, T1: Ss + 'a, T2: Ss + 'a>( effectives: (T0, T1, T2), ) -> Self::Three<'a, T0, T1, T2> where @@ -203,7 +222,7 @@ pub trait Join { pub trait TryJoin { type Effect: Effect; - type Two<'a, T0: Send + Sync + 'a, T1: Send + Sync + 'a>: Effective< + type Two<'a, T0: Ss + 'a, T1: Ss + 'a>: Effective< 'a, Output = Result<(T0::Ok, T1::Ok), T0::Err>, Effect = Self::Effect, @@ -212,7 +231,7 @@ pub trait TryJoin { T0: TryEffective<'a, Effect = Self::Effect>, T1: TryEffective<'a, Err = T0::Err, Effect = Self::Effect>; - type Three<'a, T0: Send + Sync + 'a, T1: Send + Sync + 'a, T2: Send + Sync + 'a>: Effective< + type Three<'a, T0: Ss + 'a, T1: Ss + 'a, T2: Ss + 'a>: Effective< 'a, Output = Result<(T0::Ok, T1::Ok, T2::Ok), T0::Err>, Effect = Self::Effect, @@ -222,13 +241,7 @@ pub trait TryJoin { T1: TryEffective<'a, Err = T0::Err, Effect = Self::Effect>, T2: TryEffective<'a, Err = T0::Err, Effect = Self::Effect>; - fn two< - 'a, - T0: Send + Sync + 'a, - T1: Send + Sync + 'a, - F0: Send + Sync + 'a, - F1: Send + Sync + 'a, - >( + fn two<'a, T0: Ss + 'a, T1: Ss + 'a, F0: Ss + 'a, F1: Ss + 'a>( cb: (F0, F1), ) -> Self::Two<'a, T0, T1> where @@ -237,15 +250,7 @@ pub trait TryJoin { F0: FnOnce() -> T0, F1: FnOnce() -> T1; - fn three< - 'a, - T0: Send + Sync + 'a, - T1: Send + Sync + 'a, - T2: Send + Sync + 'a, - F0: Send + Sync + 'a, - F1: Send + Sync + 'a, - F2: Send + Sync + 'a, - >( + fn three<'a, T0: Ss + 'a, T1: Ss + 'a, T2: Ss + 'a, F0: Ss + 'a, F1: Ss + 'a, F2: Ss + 'a>( cb: (F0, F1, F2), ) -> Self::Three<'a, T0, T1, T2> where @@ -343,8 +348,8 @@ where impl<'lt, E: Effect, F0, F1, T0, T1> TryJoinable<'lt, E> for (F0, F1) where - F0: FnOnce() -> T0 + Send + Sync + 'lt, - F1: FnOnce() -> T1 + Send + Sync + 'lt, + F0: FnOnce() -> T0 + Ss + 'lt, + F1: FnOnce() -> T1 + Ss + 'lt, T0: TryEffective<'lt, Effect = E>, T1: TryEffective<'lt, Err = T0::Err, Effect = E>, { |