Struct stepflow::Session[][src]

pub struct Session { /* fields omitted */ }

Sessions both define a flow and execute them.

Sessions can be thought of as two parts:

  1. Definition of the flow
  2. Execution of the flow


let mut session = Session::new(SessionId::new(0));

// Define the data needed from the flow by registering variables
let var_id = session.var_store_mut().insert_new_named("my_var", |id| Ok(StringVar::new(id).boxed())).unwrap();

// Define the steps that will get that data and insert it in the root step
let step_id = session.step_store_mut().insert_new(|id| Ok(Step::new(id, None, vec![var_id]))).unwrap();
// Define the actions that will fulfill that data and set it as the default action
let action_id = session.action_store().insert_new(|id| Ok(HtmlFormAction::new(id, Default::default()).boxed())).unwrap();
session.set_action_for_step(action_id, None);
// Start the session!
let advance_result = session.advance(None);
assert!(matches!(advance_result, Ok(AdvanceBlockedOn::ActionStartWith(_, _html))));

// From here, typically you'd display the form and call session.advance() with the form results


impl Session[src]

pub fn new(id: SessionId) -> Session[src]

Create a new Session

pub fn with_capacity(
    id: SessionId,
    var_capacity: usize,
    step_capacity: usize,
    action_capacity: usize
) -> Session

Create a new session with capacities defined for each contained ObjectStore

pub fn id(&self) -> &SessionId[src]

Get the ID of the Session

pub fn state_data(&self) -> &StateData[src]

Get the current session data

pub fn current_step(&self) -> Result<&StepId, Error>[src]

pub fn step_store(&self) -> &ObjectStore<Step, StepId>[src]

Store for Steps

pub fn step_store_mut(&mut self) -> &mut ObjectStore<Step, StepId>[src]

Mutable store for Steps

pub fn push_root_substep(&mut self, step_id: StepId)[src]

Add a registered Step to the end of the root step

pub fn action_store(&self) -> &ActionObjectStore[src]

Store for Actions

pub fn var_store(
) -> &ObjectStore<Box<dyn Var + 'static + Send + Sync, Global>, VarId>

Store for Vars

pub fn var_store_mut(
    &mut self
) -> &mut ObjectStore<Box<dyn Var + 'static + Send + Sync, Global>, VarId>

Mutable store for Vars

pub fn set_action_for_step(
    &mut self,
    action_id: ActionId,
    step_id: Option<&StepId>
) -> Result<(), Error>

Set the Action for a Step

If step_id is None, it's registered as the general action for all steps. Actions are generally executed with the specific step first (if it exists) and the general step after (if the specific step cannot fulfill).

pub fn advance(
    &mut self,
    step_output: Option<(&StepId, StateData)>
) -> Result<AdvanceBlockedOn, Error>

Main function for advancing the flow to the next step.

step_output is what the current step generated and is merged with the internal current state_data before trying to advance to the next step.

Advancing works in a loop that tries to advance as far as possible until it hits a blocking condition The loop is roughly:

  • Try to enter the next step. Note: the process continues irregardless of failure
  • Execute the specific action of the current step
  • If there is no specific action or it CannotFulfill, execute the general action
  • If the action is not Finished, then we're blocked and exit the loop

Trait Implementations

impl Debug for Session[src]

impl ObjectStoreContent for Session[src]

Auto Trait Implementations

Blanket Implementations

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

impl<T> AsAny for T where
    T: Any

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

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

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.