Diffstat (limited to 'src/protocols.rs')
| -rw-r--r-- | src/protocols.rs | 82 |
1 files changed, 70 insertions, 12 deletions
diff --git a/src/protocols.rs b/src/protocols.rs index ba1e6ff..e5f0ae4 100644 --- a/src/protocols.rs +++ b/src/protocols.rs @@ -11,14 +11,54 @@ pub mod recoverable { pub enum Recoverable {} - impl<'value, 'ctx: 'value> Protocol<'value, 'ctx> for Recoverable { - type Hint = (); + impl Protocol for Recoverable { + type Hint<'value, 'ctx: 'value> = (); + + type Known<'value, 'ctx: 'value> = (); + + type Accessor< + 'walking, + 'value: 'walking, + 'ctx: 'value, + WalkerErr: 'value, + VisitorErr: 'value, + > = &'walking mut dyn Accessor<'value, 'ctx, WalkerErr, VisitorErr>; + } +} - type Known = (); +pub mod sequence { + use crate::{error::UniError, protocol::Protocol, Visitor}; - type Accessor<'walking, WalkerErr: 'value, VisitorErr: 'value> = &'walking dyn Accessor<'value, 'ctx, WalkerErr, VisitorErr> - where - 'value: 'walking; + pub struct Hint { + pub min_len: Option<usize>, + pub max_len: Option<usize>, + } + + pub struct Known { + pub len: Option<usize>, + } + + pub trait Accessor<'value, 'ctx: 'value, WalkerErr, VisitorErr> { + fn next( + &mut self, + visitor: &mut dyn Visitor<'value, 'ctx, WalkerErr, Error = VisitorErr>, + ) -> Result<(), UniError<WalkerErr, VisitorErr>>; + } + + pub enum Sequence {} + + impl Protocol for Sequence { + type Hint<'value, 'ctx: 'value> = Hint; + + type Known<'value, 'ctx: 'value> = Known; + + type Accessor< + 'walking, + 'value: 'walking, + 'ctx: 'value, + WalkerErr: 'value, + VisitorErr: 'value, + > = &'walking mut dyn Accessor<'value, 'ctx, WalkerErr, VisitorErr>; } } @@ -66,13 +106,31 @@ pub mod reference { pub struct ReferenceMut<T: ?Sized + Any>(PhantomData<fn() -> T>); - impl<'value, 'ctx: 'value, T: ?Sized + Any> Protocol<'value, 'ctx> for Reference<T> { - type Hint = Hint; + impl<T: ?Sized + Any> Protocol for Reference<T> { + type Hint<'value, 'ctx: 'value> = Hint; + + type Known<'value, 'ctx: 'value> = Known; + + type Accessor< + 'walking, + 'value: 'walking, + 'ctx: 'value, + WalkerErr: 'value, + VisitorErr: 'value, + > = Ref<'walking, 'value, 'ctx, T>; + } + + impl<T: ?Sized + Any> Protocol for ReferenceMut<T> { + type Hint<'value, 'ctx: 'value> = Hint; - type Known = Known; + type Known<'value, 'ctx: 'value> = Known; - type Accessor<'walking, WalkerErr: 'value, VisitorErr: 'value> = Ref<'walking, 'value, 'ctx, T> - where - 'value: 'walking; + type Accessor< + 'walking, + 'value: 'walking, + 'ctx: 'value, + WalkerErr: 'value, + VisitorErr: 'value, + > = Mut<'walking, 'value, 'ctx, T>; } } |