Diffstat (limited to 'src/build/builders/core/value.rs')
| -rw-r--r-- | src/build/builders/core/value.rs | 115 |
1 files changed, 65 insertions, 50 deletions
diff --git a/src/build/builders/core/value.rs b/src/build/builders/core/value.rs index dba20bd..ccca07e 100644 --- a/src/build/builders/core/value.rs +++ b/src/build/builders/core/value.rs @@ -1,5 +1,7 @@ use core::fmt::Display; +use effectful::{bound::IsSync, closure::Capture, effective::Effective, environment::{DynBind, Environment, NativeForm}, forward_send_sync, higher_ranked::Mut}; + use crate::{ any::{ AnyTrait, BorrowedMutStatic, BorrowedMutStaticHrt, BorrowedStatic, BorrowedStaticHrt, @@ -7,7 +9,6 @@ use crate::{ TempBorrowedStaticHrt, }, any_trait, - effect::{Effect, EffectExt as _, Effective as _, EffectiveExt as _, ErasedEffective, Ss}, hkt::Marker, protocol::{ visitor::{ @@ -22,6 +23,8 @@ use crate::{ #[non_exhaustive] pub struct ValueError<T>(Marker<T>); +forward_send_sync!({} {} {T} ValueError<T>); + impl<T> ::core::fmt::Debug for ValueError<T> { fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { write!(f, "missing value of type `{}`", core::any::type_name::<T>()) @@ -49,7 +52,12 @@ pub struct ValueBuilder<T, Clone, E> { _marker: Marker<(E, Clone)>, } -impl<T: Ss, Clone, E> crate::BuilderTypes for ValueBuilder<T, Clone, E> { +forward_send_sync!({T} {} {Clone, E} ValueBuilder<T, Clone, E>); + +impl<T, Clone, E: Environment> crate::BuilderTypes<E> for ValueBuilder<T, Clone, E> +where + T: DynBind<E> +{ type Error = ValueError<T>; type Value = T; @@ -57,33 +65,34 @@ impl<T: Ss, Clone, E> crate::BuilderTypes for ValueBuilder<T, Clone, E> { type Seed = (); } -impl<'ctx, T: Ss + 'static, Clone, E: Effect> crate::Builder<'ctx, E> for ValueBuilder<T, Clone, E> +impl<'ctx, T: 'static, Clone, E: Environment> crate::Builder<'ctx, E> for ValueBuilder<T, Clone, E> where - Self: AnyTrait<'ctx>, + Self: AnyTrait<'ctx, E>, + T: DynBind<E> { - fn build<'a>(self) -> ErasedEffective<'a, Result<Self::Value, Self::Error>, E> + fn build<'a>(self) -> NativeForm<'a, Result<Self::Value, Self::Error>, E> where Self: 'a, { - E::ready(self.value.ok_or(ValueError(Default::default()))) + E::value(self.value.ok_or(ValueError(Default::default()))).cast() } - fn from_seed<'a>(_seed: Self::Seed) -> ErasedEffective<'a, Self, E> + fn from_seed<'a>(_seed: Self::Seed) -> NativeForm<'a, Self, E> where Self: 'a, { - E::ready(Self { + E::value(Self { value: None, _marker: Default::default(), - }) + }).cast() } } -impl<'ctx, T: Ss + 'static, Clone, E: Effect> AsVisitor<'ctx> for ValueBuilder<T, Clone, E> +impl<'ctx, T: 'static, Clone, E: Environment> AsVisitor<'ctx, E> for ValueBuilder<T, Clone, E> where - Self: AnyTrait<'ctx>, + Self: AnyTrait<'ctx, E>, { - fn as_visitor<'a>(&'a mut self) -> DynVisitor<'a, 'ctx> + fn as_visitor<'a>(&'a mut self) -> DynVisitor<'a, 'ctx, E> where 'ctx: 'a, { @@ -92,16 +101,16 @@ where } any_trait! { - impl['ctx, T, E] ValueBuilder<T, NotCloneable, E> = [ + impl['ctx, T][E] ValueBuilder<T, NotCloneable, E> = [ RequestHintProto<E>, ValueProto<OwnedStatic<T>, E>, ] where - E: Effect, - T: Ss + 'static + E: Environment, + T: DynBind<E> + IsSync<E::NeedSend> + 'static } any_trait! { - impl['ctx, T, E] ValueBuilder<T, Cloneable, E> = [ + impl['ctx, T][E] ValueBuilder<T, Cloneable, E> = [ RequestHintProto<E>, ValueProto<OwnedStatic<T>, E>, ValueProto<BorrowedStaticHrt<T>, E>, @@ -109,39 +118,42 @@ any_trait! { ValueProto<BorrowedMutStaticHrt<T>, E>, ValueProto<TempBorrowedMutStaticHrt<T>, E>, ] where - E: Effect, - T: Ss + 'static + Clone, + E: Environment, + T: DynBind<E> + IsSync<E::NeedSend> + 'static + Clone, } -impl<'ctx, T: Ss + 'static, E: Effect> RequestHint<'ctx, E> for ValueBuilder<T, NotCloneable, E> { +impl<'ctx, T: 'static, E: Environment> RequestHint<'ctx, E> for ValueBuilder<T, NotCloneable, E> +where + T: DynBind<E> + IsSync<E::NeedSend> +{ fn request_hint<'this: 'e, 'walker: 'e, 'e>( &'this mut self, - walker: DynWalker<'walker, 'ctx>, - ) -> ErasedEffective<'e, VisitResult, E> + walker: DynWalker<'walker, 'ctx, E>, + ) -> NativeForm<'e, VisitResult, E> where 'ctx: 'this + 'walker, { - E::as_ctx((self, walker), |(this, walker)| { + E::with(Capture((self, walker)).lending_fun_mut(|(this, walker), _| { hint_protocol::<ValueProto<OwnedStatic<T>, E>, _>(walker.cast(), *this, ()).cast() - }) - .remove_ctx() + })).cast() } } -impl<'ctx, T: Ss + 'static, E: Effect> RequestHint<'ctx, E> for ValueBuilder<T, Cloneable, E> +impl<'ctx, T: 'static, E: Environment> RequestHint<'ctx, E> for ValueBuilder<T, Cloneable, E> where - T: Clone, + T: DynBind<E> + IsSync<E::NeedSend> + Clone, { fn request_hint<'this: 'e, 'walker: 'e, 'e>( &'this mut self, - walker: DynWalker<'walker, 'ctx>, - ) -> ErasedEffective<'e, VisitResult, E> + walker: DynWalker<'walker, 'ctx, E>, + ) -> NativeForm<'e, VisitResult, E> where 'ctx: 'this + 'walker, { - E::as_ctx((self, walker), |(this, walker)| { + E::value((self, walker)) + .update(Capture(()).fun_once_hrt::<Mut<_>, _>(|_, (this, walker), _| { hint_protocol::<ValueProto<OwnedStatic<T>, E>, _>(walker.cast(), *this, ()).cast() - }) + })) .if_not_finished(|(this, walker)| { hint_protocol::<ValueProto<BorrowedStaticHrt<T>, E>, _>(walker.cast(), *this, ()).cast() }) @@ -157,94 +169,97 @@ where hint_protocol::<ValueProto<TempBorrowedMutStaticHrt<T>, E>, _>(walker.cast(), *this, ()) .cast() }) - .remove_ctx() + .map(Capture(()).fun_once(|_, (_, x), _| x)) + .cast() } } -impl<'ctx, T: Ss + 'static, Clone, E: Effect> Value<'ctx, OwnedStatic<T>, E> +impl<'ctx, T: 'static, Clone, E: Environment> Value<'ctx, OwnedStatic<T>, E> for ValueBuilder<T, Clone, E> +where + T: DynBind<E> { fn visit<'a>( &'a mut self, OwnedStatic(value): OwnedStatic<T>, - ) -> ErasedEffective<'a, VisitResult<OwnedStatic<T>>, E> + ) -> NativeForm<'a, VisitResult<OwnedStatic<T>>, E> where 'ctx: 'a, { self.value = Some(value); - E::ready(Flow::Done.into()) + E::value(Flow::Done.into()).cast() } } -impl<'ctx, T: Ss + 'static, E: Effect> Value<'ctx, BorrowedStaticHrt<T>, E> +impl<'ctx, T: 'static, E: Environment> Value<'ctx, BorrowedStaticHrt<T>, E> for ValueBuilder<T, Cloneable, E> where - T: Clone, + T: Clone + DynBind<E> + IsSync<E::NeedSend>, { fn visit<'a>( &'a mut self, BorrowedStatic(value): BorrowedStatic<'ctx, T>, - ) -> ErasedEffective<'a, VisitResult<BorrowedStatic<'ctx, T>>, E> + ) -> NativeForm<'a, VisitResult<BorrowedStatic<'ctx, T>>, E> where 'ctx: 'a, { self.value = Some(value.clone()); - E::ready(Flow::Done.into()) + E::value(Flow::Done.into()).cast() } } -impl<'ctx, T: Ss + 'static, E: Effect> Value<'ctx, TempBorrowedStaticHrt<T>, E> +impl<'ctx, T: 'static, E: Environment> Value<'ctx, TempBorrowedStaticHrt<T>, E> for ValueBuilder<T, Cloneable, E> where - T: Clone, + T: Clone + DynBind<E> + IsSync<E::NeedSend>, { fn visit<'a>( &'a mut self, TempBorrowedStatic(value): TempBorrowedStatic<'a, T>, - ) -> ErasedEffective<'a, VisitResult<TempBorrowedStatic<'a, T>>, E> + ) -> NativeForm<'a, VisitResult<TempBorrowedStatic<'a, T>>, E> where 'ctx: 'a, { self.value = Some(value.clone()); - E::ready(Flow::Done.into()) + E::value(Flow::Done.into()).cast() } } -impl<'ctx, T: Ss + 'static, E: Effect> Value<'ctx, BorrowedMutStaticHrt<T>, E> +impl<'ctx, T: 'static, E: Environment> Value<'ctx, BorrowedMutStaticHrt<T>, E> for ValueBuilder<T, Cloneable, E> where - T: Clone, + T: Clone + DynBind<E> + IsSync<E::NeedSend>, { fn visit<'a>( &'a mut self, BorrowedMutStatic(value): BorrowedMutStatic<'ctx, T>, - ) -> ErasedEffective<'a, VisitResult<BorrowedMutStatic<'ctx, T>>, E> + ) -> NativeForm<'a, VisitResult<BorrowedMutStatic<'ctx, T>>, E> where 'ctx: 'a, { self.value = Some(value.clone()); - E::ready(Flow::Done.into()) + E::value(Flow::Done.into()).cast() } } -impl<'ctx, T: Ss + 'static, E: Effect> Value<'ctx, TempBorrowedMutStaticHrt<T>, E> +impl<'ctx, T: 'static, E: Environment> Value<'ctx, TempBorrowedMutStaticHrt<T>, E> for ValueBuilder<T, Cloneable, E> where - T: Clone, + T: Clone + DynBind<E> + IsSync<E::NeedSend>, { fn visit<'a>( &'a mut self, TempBorrowedMutStatic(value): TempBorrowedMutStatic<'a, T>, - ) -> ErasedEffective<'a, VisitResult<TempBorrowedMutStatic<'a, T>>, E> + ) -> NativeForm<'a, VisitResult<TempBorrowedMutStatic<'a, T>>, E> where 'ctx: 'a, { self.value = Some(value.clone()); - E::ready(Flow::Done.into()) + E::value(Flow::Done.into()).cast() } } |