Diffstat (limited to 'src/protocol.rs')
-rw-r--r--src/protocol.rs47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/protocol.rs b/src/protocol.rs
index 33d73be..822d827 100644
--- a/src/protocol.rs
+++ b/src/protocol.rs
@@ -55,7 +55,50 @@
pub mod visitor;
pub mod walker;
+use core::ops::{Deref, DerefMut};
+
use crate::any::AnyTrait;
-pub type Visitor<'a, 'ctx> = &'a mut (dyn AnyTrait<'ctx> + Send + 'a);
-pub type Walker<'a, 'ctx> = &'a mut (dyn AnyTrait<'ctx> + Send + 'a);
+pub struct DynVisitor<'a, 'ctx>(pub &'a mut (dyn AnyTrait<'ctx> + Send + Sync + 'a));
+
+impl<'a, 'ctx> DynVisitor<'a, 'ctx> {
+ pub fn cast<'b>(&'b mut self) -> DynVisitor<'b, 'ctx> {
+ DynVisitor(&mut *self.0)
+ }
+}
+
+impl<'a, 'ctx> Deref for DynVisitor<'a, 'ctx> {
+ type Target = dyn AnyTrait<'ctx> + Send + Sync + 'a;
+
+ fn deref(&self) -> &Self::Target {
+ &*self.0
+ }
+}
+
+impl<'a, 'ctx> DerefMut for DynVisitor<'a, 'ctx> {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut *self.0
+ }
+}
+
+pub struct DynWalker<'a, 'ctx>(pub &'a mut (dyn AnyTrait<'ctx> + Send + Sync + 'a));
+
+impl<'a, 'ctx> DynWalker<'a, 'ctx> {
+ pub fn cast<'b>(&'b mut self) -> DynVisitor<'b, 'ctx> {
+ DynVisitor(&mut *self.0)
+ }
+}
+
+impl<'a, 'ctx> Deref for DynWalker<'a, 'ctx> {
+ type Target = dyn AnyTrait<'ctx> + Send + Sync + 'a;
+
+ fn deref(&self) -> &Self::Target {
+ &*self.0
+ }
+}
+
+impl<'a, 'ctx> DerefMut for DynWalker<'a, 'ctx> {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut *self.0
+ }
+}