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

Examples

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();
session.push_root_substep(step_id);
 
// Define the actions that will fulfill that data and set it as the default action
let action_id = session.action_store_mut().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

Implementations

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
[src]

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
) -> &ObjectStore<Box<dyn Action + 'static + Sync + Send, Global>, ActionId>
[src]

Store for Actions

pub fn action_store_mut(
    &mut self
) -> &mut ObjectStore<Box<dyn Action + 'static + Sync + Send, Global>, ActionId>
[src]

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

Store for Vars

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

Mutable store for Vars

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

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>
[src]

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

impl !RefUnwindSafe for Session

impl Send for Session

impl Sync for Session

impl Unpin for Session

impl !UnwindSafe for Session

Blanket Implementations

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

impl<T> AsAny for T where
    T: Any
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.