pub struct Driver<B: Behavior, E> { /* private fields */ }Expand description
Application core driving one behavior through one runtime port.
Uses ExclusiveExecutor for allocation-free exclusive turns. Every event
goes through turn; effect interpretation is async, outside the executor.
§Compile-time bound
The B: Behavior bound rejects a payload type that does not implement
Behavior. This is a narrow static bound, not a proof that every
invalid composition is unrepresentable:
use bombay_engine::Driver;
// `u32` does not implement `Behavior`; this must not compile.
let _: Driver<u32, ()> = Driver::new(42u32, ());Implementations§
Source§impl<B, E> Driver<B, E>
impl<B, E> Driver<B, E>
Sourcepub async fn run_init(
&mut self,
) -> Result<Option<Exit<B::Addr>>, RunError<B::Error, E::Error>>
pub async fn run_init( &mut self, ) -> Result<Option<Exit<B::Addr>>, RunError<B::Error, E::Error>>
Run initialization, construct the executor, interpret init effects.
Transitions Uninitialized → Running for a continuing behavior or
Uninitialized → Terminated for terminal initialization.
Returns the terminal exit in the latter case.
§Errors
Returns RunError::Behavior when Behavior::init fails.
Returns RunError::Environment when the environment rejects
an initialization effect.
§Panics
Panics if called on a driver that is not in the Uninitialized state.
Sourcepub async fn run_loop(
&mut self,
) -> Result<RunExit<Exit<B::Addr>>, RunError<B::Error, E::Error>>
pub async fn run_loop( &mut self, ) -> Result<RunExit<Exit<B::Addr>>, RunError<B::Error, E::Error>>
Run the event loop. Every event goes through
ExclusiveExecutor::turn.
§Errors
Returns RunError::Behavior when a Behavior::transition fails.
Returns RunError::Environment when the environment rejects an
effect.
§Panics
Panics if the driver is not in the Running state. A transition panic
unwinds through this method (leaving the executor poisoned).
Sourcepub async fn run(
&mut self,
) -> Result<RunExit<Exit<B::Addr>>, RunError<B::Error, E::Error>>
pub async fn run( &mut self, ) -> Result<RunExit<Exit<B::Addr>>, RunError<B::Error, E::Error>>
Run init, then event loop, then retire.
§Errors
Returns RunError::Behavior when the behavior fails during
initialization or a transition. Returns RunError::Environment
when the environment rejects an effect.