1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::Visitor;

/// A type buildable from a walker.
pub trait Build<'value, 'ctx>: Sized {
    type Error;

    /// The builder that can be used to build a value.
    type Builder: Builder<'value, 'ctx, Value = Self, Error = Self::Error>;
}

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

    /// Type to be built.
    type Value: Sized;

    /// Init a new builder.
    fn init() -> Self
    where
        Self: Sized;

    /// As a visitor.
    fn as_visitor<WalkerErr: 'value>(
        &mut self,
    ) -> &mut dyn Visitor<'value, 'ctx, WalkerErr, Error = Self::Error>;

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