Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs91
1 files changed, 36 insertions, 55 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f74cd44..cba864c 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,34 +3,20 @@
#[cfg(feature = "alloc")]
extern crate alloc;
-pub mod build;
+// pub mod build;
pub mod error;
-pub mod impls;
+// pub mod impls;
pub mod protocol;
-pub mod protocols;
-pub mod transform;
-pub mod walk;
+// pub mod protocols;
+// pub mod transform;
+// pub mod walk;
// use buildable::Buildable;
-use error::{UniError, WalkerError};
-use protocol::{AnyHint, AnyVisit, Hint, ProtocolDescription, ProtocolId, Visit};
+use protocol::{AnyHint, Hint, ProtocolId, Visit, AnyVisit};
// pub use buildable::Buildable;
// pub use walkable::{Walkable, WalkableMut, WalkableRef};
-/// Token value showing a hint was given.
-///
-/// This is used by [`Visitor::request_hint`] to tell the walker if a hint
-/// was given or not. A `Some(HintGiven)` means the visitor gave a hint by
-/// calling a [`Hint::hint`] method. A `None` means the visitor did not
-/// give a hint to the walker for what protocol to use.
-///
-/// [`Hint::hint`] methods return an instance of this type so [`Visitor::request_hint`]
-/// can just return that instance.
-#[must_use]
-#[derive(Debug)]
-pub struct HintGiven;
-
/// Status of a walker after walking using a visitor.
///
/// Some walkers can be walked multiple times to extract multiple
@@ -41,15 +27,17 @@ pub enum WalkStatus {
/// Attemping to call `walk` is likely to result in an error.
Done,
- /// The walker can continue.
- Continue,
+ /// The walker has more values to walk.
+ More,
+
+ /// The walker will repeat values.
+ Repeat,
+
+ Error,
}
/// Walker over a value with lifetime `'value`.
-pub trait Walker<'value, 'ctx: 'value, VisitorErr> {
- /// Error type the walker generates.
- type Error;
-
+pub trait Walker<'ctx> {
/// Walk the walker over the value.
///
/// This is the main entrypoint for walking a value.
@@ -61,34 +49,33 @@ pub trait Walker<'value, 'ctx: 'value, VisitorErr> {
/// [`Visitor::request_hint`] before using walker specific logic to pick a protocol.
fn walk(
&mut self,
- visitor: &mut dyn Visitor<'value, 'ctx, Self::Error, Error = VisitorErr>,
- ) -> Result<WalkStatus, UniError<Self::Error, VisitorErr>>;
+ visitor: &mut dyn Visitor<'ctx>,
+ ) -> WalkStatus;
+}
- fn all_protocols() -> impl Iterator<Item = ProtocolDescription>
- where
- Self: Sized;
+pub trait ErrorNeedsHint {
+ fn error_needs_hint(&mut self);
}
-pub fn walk_with_hints<'value, 'ctx: 'value, VisitorErr, H: WalkerHints<'value, 'ctx, VisitorErr>>(
+pub fn walk_with_hints<'ctx, H: WalkerHints<'ctx>>(
hints: &mut H,
- visitor: &mut dyn Visitor<'value, 'ctx, H::Error, Error = VisitorErr>,
-) -> Result<WalkStatus, UniError<H::Error, VisitorErr>>
+ visitor: &mut dyn Visitor<'ctx>,
+) -> WalkStatus
where
- H::Error: WalkerError<'value, 'ctx>,
+ H: ErrorNeedsHint,
{
// Request that the visitor give us a hint of what protocol to use.
- match visitor.request_hint(hints, true)? {
- Some(HintGiven) => Ok(WalkStatus::Done),
- None => Err(UniError::Walker(
- <H::Error as WalkerError<'value, 'ctx>>::needs_hint(),
- )),
+ match visitor.request_hint(hints, true) {
+ Some(status) => status,
+ None => {
+ hints.error_needs_hint();
+ WalkStatus::Error
+ },
}
}
/// Hint lookup for a walker.
-pub trait WalkerHints<'value, 'ctx: 'value, VisitorErr> {
- type Error;
-
+pub trait WalkerHints<'ctx> {
/// Query the walker for a given protocol.
///
/// If the walker doesn't support the protocol then a `None` is returned.
@@ -97,13 +84,11 @@ pub trait WalkerHints<'value, 'ctx: 'value, VisitorErr> {
fn protocol(
&mut self,
id: ProtocolId,
- ) -> Option<AnyHint<'_, 'value, 'ctx, Self::Error, VisitorErr>>;
+ ) -> Option<AnyHint<'_, 'ctx>>;
}
/// Visitor over a value to be built.
-pub trait Visitor<'value, 'ctx: 'value, WalkerErr> {
- type Error;
-
+pub trait Visitor<'ctx> {
/// Request the visitor hint what protocol to use.
///
/// It is not recommended to call this while in a protocol hint as a walker.
@@ -115,12 +100,12 @@ pub trait Visitor<'value, 'ctx: 'value, WalkerErr> {
/// A return value of `Ok(None)` means no hint was given to the walker.
fn request_hint(
&mut self,
- hints: &mut dyn WalkerHints<'value, 'ctx, Self::Error, Error = WalkerErr>,
+ hints: &mut dyn WalkerHints<'ctx>,
need_hint: bool,
- ) -> Result<Option<HintGiven>, UniError<WalkerErr, Self::Error>> {
+ ) -> Option<WalkStatus> {
let _ = hints;
let _ = need_hint;
- Ok(None)
+ None
}
/// Query the visitor for a given protocol.
@@ -129,9 +114,5 @@ pub trait Visitor<'value, 'ctx: 'value, WalkerErr> {
fn protocol(
&mut self,
id: ProtocolId,
- ) -> Option<AnyVisit<'_, 'value, 'ctx, WalkerErr, Self::Error>>;
-
- fn all_protocols() -> impl Iterator<Item = ProtocolDescription>
- where
- Self: Sized;
+ ) -> Option<AnyVisit<'_, 'ctx>>;
}