pub mod recoverable {
use crate::{protocol::Protocol, ControlFlow, Visitor};
pub trait Accessor<'ctx> {
/// Each time this is called the walker resets.
fn new_walk(&mut self, visitor: &mut dyn Visitor<'ctx>) -> ControlFlow;
}
pub enum Recoverable {}
impl Protocol for Recoverable {
type Hint<'ctx> = ();
type Known<'ctx> = ();
type Accessor<'walking, 'ctx: 'walking> = &'walking mut dyn Accessor<'ctx>;
}
}
pub mod sequence {
use crate::{protocol::Protocol, ControlFlow, Visitor};
pub struct Hint {
pub min_len: Option<usize>,
pub max_len: Option<usize>,
}
pub struct Known {
pub len: Option<usize>,
}
pub trait Accessor<'ctx> {
fn next(&mut self, visitor: &mut dyn Visitor<'ctx>) -> ControlFlow;
}
pub enum Sequence {}
impl Protocol for Sequence {
type Hint<'ctx> = Hint;
type Known<'ctx> = Known;
type Accessor<'walking, 'ctx: 'walking> = &'walking mut dyn Accessor<'ctx>;
}
}
pub mod reference {
use core::{any::Any, marker::PhantomData};
use crate::protocol::Protocol;
pub enum Kind {
Walking,
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 Ref<'walking, 'ctx, T: ?Sized + Any> {
Walking(&'walking T),
Context(&'ctx T),
Static(&'static T),
}
pub enum Mut<'walking, 'ctx, T: ?Sized + Any> {
Walking(&'walking 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<T: ?Sized + Any> Protocol for Reference<T> {
type Hint<'ctx> = Hint;
type Known<'ctx> = Known;
type Accessor<'walking, 'ctx: 'walking> = Ref<'walking, 'ctx, T>;
}
impl<T: ?Sized + Any> Protocol for ReferenceMut<T> {
type Hint<'ctx> = Hint;
type Known<'ctx> = Known;
type Accessor<'walking, 'ctx: 'walking> = Mut<'walking, 'ctx, T>;
}
}