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
use crate::*;

#[derive(Debug, Clone)]
pub struct Message<A: Scanner>(A, Expected<A::Input>);

impl<A: Scanner> Message<A> {
    pub(crate) fn new(a: A, msg: Expected<A::Input>) -> Self {
        Self(a, msg)
    }
}

impl<A: Scanner> Scanner for Message<A>
where
    A::Input: Clone,
{
    type Input = A::Input;
    type Output = A::Output;

    fn scan(&self, stream: &mut Stream<Self::Input>) -> Res<Self> {
        self.0.scan(stream).map_err(|mut err| {
            err.expected = self.1.clone();
            err
        })
    }
}