1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
pub mod builders;
pub mod protocols;

use crate::protocol::Implementer;

/// A type buildable from a walker.
pub trait Build<'ctx>: Sized {
    /// The builder that can be used to build a value.
    type Builder: Builder<'ctx, Value = Self>;
}

/// Extension to [`Visitor`] that allows constructing and finishing the visitor.
pub trait Builder<'ctx>: Default {
    type Error;

    /// Type to be built.
    type Value;

    /// As a visitor.
    fn as_visitor(&mut self) -> &mut dyn Implementer<'ctx>;

    /// Finish the value.
    fn build(self) -> Result<Self::Value, Self::Error>;
}