Skip to main content

Driver

Struct Driver 

Source
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>
where B: Behavior,

Source

pub fn new(behavior: B, environment: E) -> Self

Source§

impl<B, E> Driver<B, E>
where B: Behavior<Ph = Never> + Send, B::Event: Send, E: Environment<Event = B::Event, Effect = RuntimeEffects<B::Addr, B::Sends, B::Birth>>,

Source

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.

Source

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).

Source

pub async fn retire(&mut self)

Retire the environment.

Source

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.

Auto Trait Implementations§

§

impl<B, E> Freeze for Driver<B, E>
where E: Freeze, B: Freeze,

§

impl<B, E> RefUnwindSafe for Driver<B, E>

§

impl<B, E> Send for Driver<B, E>
where E: Send, B: Send,

§

impl<B, E> Sync for Driver<B, E>
where E: Sync, B: Sync,

§

impl<B, E> Unpin for Driver<B, E>
where E: Unpin, B: Unpin,

§

impl<B, E> UnsafeUnpin for Driver<B, E>
where E: UnsafeUnpin, B: UnsafeUnpin,

§

impl<B, E> UnwindSafe for Driver<B, E>
where E: UnwindSafe, B: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.