Stateful

Trait Stateful 

Source
pub trait Stateful<CONTEXT, STATE> {
    // Required methods
    fn from_parts(context: CONTEXT, state: STATE) -> Self
       where Self: Sized + 'static;
    fn into_parts(self) -> (CONTEXT, STATE);
    fn context(&self) -> &CONTEXT;
    fn state(&self) -> &STATE;
    fn state_mut(&mut self) -> &mut STATE;

    // Provided method
    fn configure<I1: Into<CONTEXT>, I2: Into<STATE>>(
        context: I1,
        initial_state: I2,
    ) -> Self
       where Self: Sized + 'static { ... }
}
Expand description

A shared interface of objects that provide access to an immutable CONTEXT and mutable STATE.

Required Methods§

Source

fn from_parts(context: CONTEXT, state: STATE) -> Self
where Self: Sized + 'static,

Create new Stateful instance from CONTEXT and STATE.

Source

fn into_parts(self) -> (CONTEXT, STATE)

Destruct the Stateful instance into CONTEXT and STATE objects.

Source

fn context(&self) -> &CONTEXT

Access to the underlying immutable CONTEXT.

Source

fn state(&self) -> &STATE

Access to the underlying STATE.

Source

fn state_mut(&mut self) -> &mut STATE

Access to the underlying STATE as a mutable reference.

Keep in mind that having a consistent state is important for the correctness of Algorithm and GenAlgorithm. You should modify the internal state of a Stateful object only in rare, well-defined situations.

Provided Methods§

Source

fn configure<I1: Into<CONTEXT>, I2: Into<STATE>>( context: I1, initial_state: I2, ) -> Self
where Self: Sized + 'static,

Create new Stateful instance using values that can be converted to CONTEXT and STATE.

Implementors§

Source§

impl<CONTEXT, STATE, ITEM, STEP: GeneratorStep<CONTEXT, STATE, ITEM>> Stateful<CONTEXT, STATE> for Generator<CONTEXT, STATE, ITEM, STEP>

Source§

impl<CONTEXT, STATE, OUTPUT, STEP: ComputationStep<CONTEXT, STATE, OUTPUT>> Stateful<CONTEXT, STATE> for Computation<CONTEXT, STATE, OUTPUT, STEP>