bombay_engine/environment.rs
1//! Runtime port: events in, transition effects out, then explicit retirement.
2
3use core::future::Future;
4
5/// Gives a process protocol its live or simulated meaning.
6///
7/// Unlike narrower ingress ports, an environment also owns effect
8/// interpretation and the ordering between input and effects.
9pub trait Environment {
10 /// Events supplied to the behavior.
11 type Event;
12 /// Effects emitted by the behavior in one transition.
13 type Effect;
14 /// Failure while interpreting an effect.
15 type Error;
16
17 /// Produce the next event, or `None` when the source is closed.
18 fn next(&mut self) -> impl Future<Output = Option<Self::Event>> + Send;
19
20 /// Interpret one successful transition's complete effect.
21 fn interpret(
22 &mut self,
23 effect: Self::Effect,
24 ) -> impl Future<Output = Result<(), Self::Error>> + Send;
25
26 /// Retire resources that must be gone before terminal publication.
27 fn retire(&mut self) -> impl Future<Output = ()> + Send;
28}