Diffstat (limited to 'src/protocol/visitor/value.rs')
| -rw-r--r-- | src/protocol/visitor/value.rs | 104 |
1 files changed, 47 insertions, 57 deletions
diff --git a/src/protocol/visitor/value.rs b/src/protocol/visitor/value.rs index dd2def1..3265cdd 100644 --- a/src/protocol/visitor/value.rs +++ b/src/protocol/visitor/value.rs @@ -3,13 +3,11 @@ //! In some sense, this is the most basic protocol. use effectful::{ - bound::Dynamic, effective::{Canonical, Effective}, environment::Environment, higher_ranked::{for_lt, Rank1}, DynBind, SendSync + effective::{Canonical, Effective}, environment::Environment, higher_ranked::{for_lt, Rank1}, DynBind, SendSync }; use crate::{ - any::type_name, - hkt::Marker, - protocol::{walker::hint::HintMeta, DynVisitor}, + any::type_name, protocol::{walker::hint::HintMeta, DynVisitor} }; use super::VisitResult; @@ -17,7 +15,7 @@ use super::VisitResult; /// Trait object for the [`Value`] protocol. /// /// Types implementing the [`Value`] protocol will implement this trait. -pub trait Value<'ctx, T: ?Sized + type_name::Static, E: Environment>: DynBind<E> { +pub trait Value<'src, T: ?Sized + type_name::Static, E: Environment>: DynBind<E> { /// Visit a value of type `T`. /// /// Use this to give a value to a visitor. Its expected that a walker @@ -27,82 +25,74 @@ pub trait Value<'ctx, T: ?Sized + type_name::Static, E: Environment>: DynBind<E> /// If a [`ControlFlow::Break`] is returned then the walker /// should stop walking as soon as possible as there has likely been /// and error. - fn visit<'this: 'value, 'value: 'e, 'e>( - &'this mut self, - value: type_name::Lowered<'value, 'ctx, T>, - ) -> Canonical<'e, VisitResult<Dynamic<type_name::Lowered<'value, 'ctx, T>>>, E> + fn visit<'r>( + &'r mut self, + value: type_name::Lowered<'r, 'src, T>, + ) -> Canonical<'r, VisitResult<type_name::Lowered<'r, 'src, T>>, E> where - type_name::Lowered<'value, 'ctx, T>: Sized, - Dynamic<type_name::Lowered<'value, 'ctx, T>>: DynBind<E>, - 'ctx: 'this + 'value; + type_name::Lowered<'r, 'src, T>: Sized + DynBind<E>; } -const _: () = { - pub struct ValueProto<T: ?Sized, E>(Marker<(*const T, E)>); - - impl<'a, 'ctx, T: ?Sized, E> type_name::Lower<'a, 'ctx, &'a &'ctx ()> for ValueProto<T, E> - where - E: Environment, - T: type_name::Static, - { - type Lowered = dyn Value<'ctx, T, E> + 'a; - } +impl<'u, 'src, T: ?Sized, E> type_name::Lower<'u, 'src, &'u &'src ()> for dyn Value<'static, T, E> +where + E: Environment, + T: type_name::Static, +{ + type Lowered = dyn Value<'src, T, E> + 'u; +} - impl<'a, 'ctx, T: ?Sized, E> type_name::Raise<'a, 'ctx, &'a &'ctx ()> for dyn Value<'ctx, T, E> + 'a - where - E: Environment, - T: type_name::Static, - { - type Raised = ValueProto<T, E>; - } +impl<'u, 'src, T: ?Sized, E> type_name::Raise<'u, 'src, &'u &'src ()> for dyn Value<'src, T, E> + 'u +where + E: Environment, + T: type_name::Static, +{ + type Raised = dyn Value<'static, T, E>; +} - // This enrolls the Value protocol into the walker hint system. - impl<T, E: Environment> HintMeta for ValueProto<T, E> - where - T: ?Sized + type_name::Static, - { - type Known = for_lt!(<'b> ValueKnown<'b, T>); +// This enrolls the Value protocol into the walker hint system. +impl<T, E: Environment> HintMeta for dyn Value<'static, T, E> +where + T: ?Sized + type_name::Static, +{ + type Known = for_lt!(<'b> ValueKnown<'b, T>); - type Hint = Rank1<()>; - } + type Hint = Rank1<()>; +} - impl<T: ?Sized, E: Environment> effectful::environment::InEnvironment for ValueProto<T, E> { - type Env = E; - } -}; +impl<T: ?Sized, E: Environment> effectful::environment::InEnvironment for dyn Value<'static, T, E> { + type Env = E; +} #[derive(Copy, Clone, PartialEq, Debug, SendSync)] -pub struct ValueKnown<'a, T: ?Sized> { +pub struct ValueKnown<'src, T: ?Sized> { /// A preview of the value. /// /// This can be used to inspect the value before committing to a visit. - pub preview: Option<Dynamic<&'a T>>, + pub preview: Option<&'src T>, } pub fn visit_value< - 'ctx: 'visitor, - 'visitor: 'e, - 'lt: 'e, - 'e, - T: type_name::WithLt<'e, 'ctx>, - E: Environment, + 'r, 'src, + T, + E, >( - visitor: DynVisitor<'visitor, 'lt, 'ctx, E>, + visitor: DynVisitor<'r, 'src, E>, value: T, -) -> Canonical<'e, VisitResult<Dynamic<T>>, E> +) -> Canonical<'r, VisitResult<T>, E> where - Dynamic<T>: DynBind<E>, - type_name::Raised<'e, 'ctx, T>: type_name::Static, + E: Environment, + T: type_name::WithLt<'r, 'src> + DynBind<E>, + type_name::Raised<'r, 'src, T>: type_name::Static, { if let Some(object) = visitor - .0 - .cast_mut() - .upcast_mut::<dyn Value<'ctx, type_name::Raised<'e, 'ctx, T>, E> + '_>() + .into_inner() + .as_any_trait_mut() + .upcast_mut::<dyn Value<'src, type_name::Raised<'r, 'src, T>, E> + '_>() { // Allow the visitor to give a hint if it wants. object.visit(value) } else { // If the visitor doesn't support request hint then we continue. - E::value(VisitResult::Skipped(Dynamic(value))).cast() + E::value(VisitResult::Skipped(value)).cast() } } |