Diffstat (limited to 'src/walk/walkers/core/value.rs')
| -rw-r--r-- | src/walk/walkers/core/value.rs | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/src/walk/walkers/core/value.rs b/src/walk/walkers/core/value.rs index 9baea0e..3067a3d 100644 --- a/src/walk/walkers/core/value.rs +++ b/src/walk/walkers/core/value.rs @@ -2,10 +2,11 @@ use effectful::{ bound::IsSync, effective::Effective, environment::{DynBind, Environment, NativeForm}, SendSync, + bound::Dynamic }; use crate::{ - any::{BorrowedStatic, OwnedStatic, TempBorrowedStatic}, + any::{BorrowedStatic, OwnedStatic, TempBorrowedStatic, BorrowedStaticHrt, TempBorrowedStaticHrt}, never::Never, protocol::{ visitor::{visit_value, EffectiveVisitExt as _, VisitResult}, @@ -18,13 +19,13 @@ use crate::{ /// Primitive types use this walker as their main walker. /// This walker doesn't consider it an error if the visitor doesn't have the protocol. #[derive(Debug, SendSync)] -pub struct ValueWalker<T>(T); +pub struct ValueWalker<T>(Dynamic<T>); impl<T> ValueWalker<T> { /// Create walker from a value. #[inline(always)] pub fn new(value: T) -> Self { - Self(value) + Self(Dynamic(value)) } } @@ -44,7 +45,8 @@ impl<T: Copy> From<&T> for ValueWalker<T> { impl<'ctx, T: 'static, E: Environment> crate::Walker<'ctx, E> for ValueWalker<T> where - T: DynBind<E>, + Dynamic<T>: DynBind<E>, + Dynamic<OwnedStatic<T>>: DynBind<E>, { type Error = Never; @@ -56,7 +58,7 @@ where visitor: DynVisitor<'b, 'ctx, E>, ) -> NativeForm<'c, Result<Self::Output, Self::Error>, E> { // Attempt to visit using the value protocol. - visit_value::<_, E>(visitor, OwnedStatic(self.0)) + visit_value::<OwnedStatic<T>, E>(visitor, OwnedStatic(self.0.0)) .map((), |_, _| Ok(())) .cast() } @@ -66,24 +68,26 @@ where /// /// This walker supports values borrowed for `'ctx` or longer. #[derive(SendSync)] -pub struct BorrowWalker<'ctx, T: ?Sized>(&'ctx T); +pub struct BorrowWalker<'ctx, T: ?Sized>(Dynamic<&'ctx T>); impl<'ctx, T: ?Sized> BorrowWalker<'ctx, T> { /// Create walker from a value. #[inline(always)] pub fn new(value: &'ctx T) -> Self { - Self(value) + Self(Dynamic(value)) } } -impl<'ctx, T: ?Sized + DynBind<E> + 'static, E: Environment> crate::Walker<'ctx, E> +impl<'ctx, T: ?Sized + 'static, E: Environment> crate::Walker<'ctx, E> for BorrowWalker<'ctx, T> where - T: IsSync<E::NeedSend>, + Dynamic<&'ctx T>: DynBind<E>, + Dynamic<BorrowedStatic<'ctx, T>>: DynBind<E>, + for<'a> Dynamic<TempBorrowedStatic<'a, T>>: DynBind<E> { type Error = Never; - type Output = &'ctx T; + type Output = Dynamic<&'ctx T>; #[inline(always)] fn walk<'b: 'c, 'c>( @@ -93,12 +97,12 @@ where // Attempt to visit using the value protocol. E::value((self, visitor)) .update((), |_, (this, visitor)| { - visit_value::<_, E>(visitor.cast(), BorrowedStatic(this.0)) + visit_value::<_, E>(visitor.cast(), BorrowedStatic(this.0.0)) .map((), |_, x| VisitResult::unit_skipped(x)) .cast() }) .if_skipped((), |_, (this, visitor)| { - visit_value::<_, E>(visitor.cast(), TempBorrowedStatic(this.0)) + visit_value::<_, E>(visitor.cast(), TempBorrowedStatic(this.0.0)) .map((), |_, x| VisitResult::unit_skipped(x)) .cast() }) |