pub struct Engine<S: EffectSink, O: StepObserver = ()> { /* private fields */ }Expand description
The reducer, its state, and where its commands go.
Implementations§
Source§impl<S: EffectSink> Engine<S, ()>
impl<S: EffectSink> Engine<S, ()>
Source§impl<S: EffectSink, O: StepObserver> Engine<S, O>
impl<S: EffectSink, O: StepObserver> Engine<S, O>
Sourcepub fn with_observer<O2: StepObserver>(self, observer: O2) -> Engine<S, O2>
pub fn with_observer<O2: StepObserver>(self, observer: O2) -> Engine<S, O2>
Attach something that watches every message before the reducer sees it.
Sourcepub const fn state(&self) -> &State
pub const fn state(&self) -> &State
The current reducer state.
§Panics
Only if an earlier reduction panicked inside the reducer, which is what would leave the engine without a state. Every use of the engine after that is already a bug.
Sourcepub const fn state_mut(&mut self) -> &mut State
pub const fn state_mut(&mut self) -> &mut State
Direct state access for the bootstrap window — seeding a conversation, stamping a scratchpad path — before the first message is pumped.
§Panics
As Engine::state.
pub const fn sink_mut(&mut self) -> &mut S
Sourcepub fn into_parts(self) -> (State, S, O)
pub fn into_parts(self) -> (State, S, O)
Give everything back, so the caller can build its result, seal whatever its observer was writing, and shut the runner down.
§Panics
As Engine::state.
Sourcepub fn is_settled(&self) -> bool
pub fn is_settled(&self) -> bool
Idle, with no user prompt waiting to seed the next turn. What every headless driver means by “done”.
Sourcepub fn reduce(&mut self, now: DateTime<Local>, msg: Msg) -> StepOutcome
pub fn reduce(&mut self, now: DateTime<Local>, msg: Msg) -> StepOutcome
The kernel: stamp the clock, reduce, route the commands.
Synchronous and observer-free — --replay folds an entire recorded log
through this with no runtime, stamping each entry’s recorded timestamp
instead of reading a clock.
Sourcepub async fn step(&mut self, msg: Msg) -> StepOutcome
pub async fn step(&mut self, msg: Msg) -> StepOutcome
One message under the current wall clock, shown to the observer first.
Sourcepub async fn step_at(&mut self, now: DateTime<Local>, msg: Msg) -> StepOutcome
pub async fn step_at(&mut self, now: DateTime<Local>, msg: Msg) -> StepOutcome
Engine::step with the clock supplied by the caller — used where a
single timestamp is shared with something else, such as the recorder
line that must carry the exact now its message was reduced under.
Sourcepub async fn drive(
&mut self,
inbox: &mut Inbox<'_>,
policy: &DrivePolicy,
) -> DriveExit
pub async fn drive( &mut self, inbox: &mut Inbox<'_>, policy: &DrivePolicy, ) -> DriveExit
Pump inbox until policy says stop.
The select! is biased: cancellation and the deadline are one-shot
arms that must win against a saturated message channel. (The interactive
loop’s fairness requirement — #112, where a hot channel starved terminal
input — does not apply here, because there is no input arm to starve.)
Auto Trait Implementations§
impl<S, O> Freeze for Engine<S, O>
impl<S, O> RefUnwindSafe for Engine<S, O>where
S: RefUnwindSafe,
O: RefUnwindSafe,
impl<S, O> Send for Engine<S, O>
impl<S, O> Sync for Engine<S, O>
impl<S, O> Unpin for Engine<S, O>
impl<S, O> UnsafeUnpin for Engine<S, O>where
S: UnsafeUnpin,
O: UnsafeUnpin,
impl<S, O> UnwindSafe for Engine<S, O>where
S: UnwindSafe,
O: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more