Diffstat (limited to 'src/builtins/visitor/value.rs')
| -rw-r--r-- | src/builtins/visitor/value.rs | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/builtins/visitor/value.rs b/src/builtins/visitor/value.rs index 6a1b450..aa35891 100644 --- a/src/builtins/visitor/value.rs +++ b/src/builtins/visitor/value.rs @@ -15,7 +15,7 @@ pub struct Value<T>(PhantomData<fn() -> T>); /// Trait object for the [`Value`] protocol. /// /// Types implementing the [`Value`] protocol will implement this trait. -pub trait Object<'ctx, T> { +pub trait Object<T> { /// Visit a value of type `T`. /// /// Use this to give a value to a visitor. Its expected that a walker @@ -30,7 +30,7 @@ pub trait Object<'ctx, T> { // This is what makes Value a protocol. impl<T: 'static> Protocol for Value<T> { - type Object<'a, 'ctx: 'a> = &'a mut dyn Object<'ctx, T>; + type Object<'a, 'ctx: 'a> = &'a mut dyn Object<T>; } // This enrolls the Value protocol into the walker hint system. @@ -39,3 +39,27 @@ impl<T: 'static> Meta for Value<T> { type Hint<'a, 'ctx: 'a> = (); } + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn visit() { + struct Visitor(Option<i32>); + + impl Object<i32> for Visitor { + fn visit(&mut self, value: i32) -> ControlFlow<()> { + self.0 = Some(value); + ControlFlow::Continue(()) + } + } + + let mut v = Visitor(None); + let object: <Value<i32> as Protocol>::Object<'_, '_> = &mut v; + object.visit(42); + + assert_eq!(v.0, Some(42)); + } +} + |