pub trait Reactor {
type Reaction;
type Failure;
fn wait_for_reaction(&mut self) -> Result<Self::Reaction, Self::Failure>;
}
#[cfg(test)]
mod tests {
use super::*;
struct SequenceReactor {
next: u8,
}
impl Reactor for SequenceReactor {
type Reaction = u8;
type Failure = core::convert::Infallible;
fn wait_for_reaction(&mut self) -> Result<Self::Reaction, Self::Failure> {
let reaction = self.next;
self.next = self.next.saturating_add(1);
Ok(reaction)
}
}
#[test]
fn reactors_emit_one_physical_reaction_at_a_time() {
let mut reactor = SequenceReactor { next: 3 };
assert_eq!(reactor.wait_for_reaction(), Ok(3));
assert_eq!(reactor.wait_for_reaction(), Ok(4));
}
}