Struct Session

Source
pub struct Session { /* private fields */ }
Expand description

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§

Source§

impl Session

Source

pub fn new(id: SessionId) -> Session

Create a new Session

Source

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

Source

pub fn id(&self) -> &SessionId

Get the ID of the Session

Source

pub fn state_data(&self) -> &StateData

Get the current session data

Source

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

Source

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

Store for Steps

Source

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

Mutable store for Steps

Source

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

Add a registered Step to the end of the root step

Source

pub fn action_store( &self, ) -> &ObjectStore<Box<dyn Action + Send + Sync>, ActionId>

Store for Actions

Source

pub fn action_store_mut( &mut self, ) -> &mut ObjectStore<Box<dyn Action + Send + Sync>, ActionId>

Source

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

Store for Vars

Source

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

Mutable store for Vars

Source

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

Source

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§

Source§

impl Debug for Session

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl ObjectStoreContent for Session

Auto Trait Implementations§

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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

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.