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::reactor::*;

/// Forwards the event to the potentially _unsized_ nested [`Reactor`].
impl<S, T> Reactor<S> for Box<T>
where
    T: Reactor<S> + ?Sized,
{
    type Output = T::Output;

    fn react(&self, state: &S) -> Self::Output {
        (**self).react(state)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::mock::*;
    use proptest::*;

    proptest! {
        #[test]
        fn react(states: Vec<u8>) {
            let reactor = Box::new(Mock::default());

            for (i, state) in states.iter().enumerate() {
                assert_eq!(reactor.react(state), Ok(()));
                assert_eq!(reactor, Box::new(Mock::new(&states[0..=i])))
            }
        }
    }
}