reducer/reactor/
boxed.rs

1use crate::reactor::*;
2use alloc::boxed::Box;
3
4/// Forwards the event to the potentially _unsized_ nested [`Reactor`] (requires [`alloc`]).
5///
6/// [`alloc`]: index.html#optional-features
7impl<S, T> Reactor<S> for Box<T>
8where
9    S: ?Sized,
10    T: Reactor<S> + ?Sized,
11{
12    type Error = T::Error;
13
14    fn react(&mut self, state: &S) -> Result<(), Self::Error> {
15        (**self).react(state)
16    }
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22    use mockall::predicate::*;
23    use test_strategy::proptest;
24
25    #[proptest]
26    fn react(state: u8, result: Result<(), u8>) {
27        let mut mock = MockReactor::new();
28
29        mock.expect_react()
30            .with(eq(state))
31            .once()
32            .return_const(result);
33
34        let mut reactor = Box::new(mock);
35        assert_eq!(Reactor::react(&mut reactor, &state), result);
36    }
37}