lazy_template/errors/
skip_or_fatal.rs

1/// Return type of [`IntoSkipOrFatal::into_skip_or_fatal`].
2pub enum SkipOrFatal<Skip, Fatal> {
3    Skip(Skip),
4    Fatal(Fatal),
5}
6
7/// Trait of error type of a component parser.
8/// It checks whether the error means "skip" or "fatal".
9pub trait IntoSkipOrFatal {
10    /// "Skip" means that the parent parser may either try to parse the next type of component or error,
11    type Skip;
12    /// "Fatal" means that the parent parser should bail immediately.
13    type Fatal;
14    /// Check whether the error returned from a component parser is skip or fatal.
15    fn into_skip_or_fatal(self) -> SkipOrFatal<Self::Skip, Self::Fatal>;
16}
17
18impl<Skip, Fatal> IntoSkipOrFatal for SkipOrFatal<Skip, Fatal> {
19    type Skip = Skip;
20    type Fatal = Fatal;
21    fn into_skip_or_fatal(self) -> Self {
22        self
23    }
24}
25
26impl<Error> IntoSkipOrFatal for Option<Error> {
27    type Skip = ();
28    type Fatal = Error;
29    fn into_skip_or_fatal(self) -> SkipOrFatal<Self::Skip, Self::Fatal> {
30        match self {
31            None => SkipOrFatal::Skip(()),
32            Some(error) => SkipOrFatal::Fatal(error),
33        }
34    }
35}