use crate::{Actions, Address, MailAddr, Never, NoBirths, Step, Stopped};
pub struct Effect<S, A: Address = MailAddr> {
actions: Actions<A, Never, Vec<S>, NoBirths>,
}
impl<S, A: Address> Effect<S, A> {
#[must_use]
pub fn none() -> Self {
Self {
actions: Actions::cont(),
}
}
#[must_use]
pub fn send(send: S) -> Self {
Self {
actions: Actions::send(vec![send]),
}
}
#[must_use]
pub fn send_all(sends: impl IntoIterator<Item = S>) -> Self {
Self {
actions: Actions::send(sends.into_iter().collect()),
}
}
#[must_use]
pub fn stop(mut self) -> Self {
self.actions.become_ = Step::Stop(Stopped);
self
}
}
impl<S, A: Address> From<Effect<S, A>> for Actions<A, Never, Vec<S>, NoBirths> {
fn from(effect: Effect<S, A>) -> Self {
effect.actions
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn conversion_preserves_send_order_and_terminal_decision() {
let actions: Actions<MailAddr, Never, Vec<u8>, NoBirths> =
Effect::send_all([2, 3, 5]).stop().into();
assert_eq!(actions.sends, [2, 3, 5]);
assert!(matches!(actions.become_, Step::Stop(Stopped)));
assert!(actions.creates.is_empty());
}
}