Diffstat (limited to 'src/protocols.rs')
-rw-r--r--src/protocols.rs47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/protocols.rs b/src/protocols.rs
index 0da527f..ba1e6ff 100644
--- a/src/protocols.rs
+++ b/src/protocols.rs
@@ -1,58 +1,77 @@
pub mod recoverable {
- use crate::*;
+ use crate::{error::UniError, protocol::Protocol, Visitor};
- pub trait Accessor<'value, Err> {
+ pub trait Accessor<'value, 'ctx: 'value, WalkerErr, VisitorErr> {
/// Each time this is called the walker resets.
- fn walk_new(&mut self, visitor: &mut dyn Visitor<'value, Err>) -> Result<(), Err>;
+ fn walk_new(
+ &mut self,
+ visitor: &mut dyn Visitor<'value, 'ctx, WalkerErr, Error = VisitorErr>,
+ ) -> Result<(), UniError<WalkerErr, VisitorErr>>;
}
pub enum Recoverable {}
- impl<'value> Protocol<'value> for Recoverable {
+ impl<'value, 'ctx: 'value> Protocol<'value, 'ctx> for Recoverable {
type Hint = ();
type Known = ();
- type Accessor<'walking, Err: Error<'value>> = &'walking dyn Accessor<'value, Err>
+ type Accessor<'walking, WalkerErr: 'value, VisitorErr: 'value> = &'walking dyn Accessor<'value, 'ctx, WalkerErr, VisitorErr>
where
'value: 'walking;
}
}
-pub mod str {
- use crate::*;
+pub mod reference {
+ use core::{any::Any, marker::PhantomData};
+
+ use crate::protocol::Protocol;
pub enum Kind {
Walking,
Value,
+ Context,
Static,
}
pub struct Hint {
pub kind: Option<Kind>,
+
pub min_len: Option<usize>,
pub max_len: Option<usize>,
}
pub struct Known {
pub kind: Option<Kind>,
+
+ /// For dynamically sized types.
pub len: Option<usize>,
}
- pub enum Data<'walking, 'value> {
- Walking(&'walking str),
- Value(&'value str),
- Static(&'static str),
+ pub enum Ref<'walking, 'value: 'walking, 'ctx: 'value, T: ?Sized + 'static> {
+ Walking(&'walking T),
+ Value(&'value T),
+ Context(&'ctx T),
+ Static(&'static T),
}
- pub enum Str {}
+ pub enum Mut<'walking, 'value: 'walking, 'ctx: 'value, T: ?Sized + 'static> {
+ Walking(&'walking mut T),
+ Value(&'value mut T),
+ Context(&'ctx mut T),
+ Static(&'static mut T),
+ }
+
+ pub struct Reference<T: ?Sized + Any>(PhantomData<fn() -> T>);
+
+ pub struct ReferenceMut<T: ?Sized + Any>(PhantomData<fn() -> T>);
- impl<'value> Protocol<'value> for Str {
+ impl<'value, 'ctx: 'value, T: ?Sized + Any> Protocol<'value, 'ctx> for Reference<T> {
type Hint = Hint;
type Known = Known;
- type Accessor<'walking, Err: Error<'value>> = Data<'walking, 'value>
+ type Accessor<'walking, WalkerErr: 'value, VisitorErr: 'value> = Ref<'walking, 'value, 'ctx, T>
where
'value: 'walking;
}