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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::Flow;

mod recoverable;
mod request_hint;
mod sequence;
mod tag;
mod value;

pub use recoverable::*;
pub use request_hint::*;
pub use sequence::*;
pub use tag::*;
pub use value::*;

#[derive(Copy, Clone)]
#[must_use]
pub enum VisitResult<S> {
    /// The protocol was not used.
    ///
    /// This either means the visitor doesn't support the protocol at all, or
    /// it didn't want to use the protocol right now.
    Skipped(S),

    /// How control flow should proceed.
    Control(Flow),
}

impl<S> PartialEq for VisitResult<S> {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (Self::Skipped(_), Self::Skipped(_)) => true,
            (Self::Control(l0), Self::Control(r0)) => l0 == r0,
            _ => false,
        }
    }
}

impl<S> core::fmt::Debug for VisitResult<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::Skipped(_) => f.debug_tuple("Skipped").finish(),
            Self::Control(arg0) => f.debug_tuple("Control").field(arg0).finish(),
        }
    }
}

impl<S> From<Flow> for VisitResult<S> {
    fn from(value: Flow) -> Self {
        Self::Control(value)
    }
}