pub struct Session { /* private fields */ }
Expand description
Sessions both define a flow and execute them.
Sessions can be thought of as two parts:
- Definition of the flow
- 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
impl Session
Sourcepub fn with_capacity(
id: SessionId,
var_capacity: usize,
step_capacity: usize,
action_capacity: usize,
) -> 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
Sourcepub fn state_data(&self) -> &StateData
pub fn state_data(&self) -> &StateData
Get the current session data
pub fn current_step(&self) -> Result<&StepId, Error>
Sourcepub fn step_store(&self) -> &ObjectStore<Step, StepId>
pub fn step_store(&self) -> &ObjectStore<Step, StepId>
Store for Step
s
Sourcepub fn step_store_mut(&mut self) -> &mut ObjectStore<Step, StepId>
pub fn step_store_mut(&mut self) -> &mut ObjectStore<Step, StepId>
Mutable store for Step
s
Sourcepub fn push_root_substep(&mut self, step_id: StepId)
pub fn push_root_substep(&mut self, step_id: StepId)
Add a registered Step
to the end of the root step
Sourcepub fn action_store(
&self,
) -> &ObjectStore<Box<dyn Action + Send + Sync>, ActionId>
pub fn action_store( &self, ) -> &ObjectStore<Box<dyn Action + Send + Sync>, ActionId>
Store for Action
s
pub fn action_store_mut( &mut self, ) -> &mut ObjectStore<Box<dyn Action + Send + Sync>, ActionId>
Sourcepub fn var_store_mut(
&mut self,
) -> &mut ObjectStore<Box<dyn Var + Send + Sync>, VarId>
pub fn var_store_mut( &mut self, ) -> &mut ObjectStore<Box<dyn Var + Send + Sync>, VarId>
Mutable store for Var
s
Sourcepub fn set_action_for_step(
&mut self,
action_id: ActionId,
step_id: Option<&StepId>,
) -> Result<(), Error>
pub fn set_action_for_step( &mut self, action_id: ActionId, step_id: Option<&StepId>, ) -> Result<(), Error>
Sourcepub fn advance(
&mut self,
step_output: Option<(&StepId, StateData)>,
) -> Result<AdvanceBlockedOn, Error>
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§
Auto Trait Implementations§
impl !Freeze for Session
impl !RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl !UnwindSafe for Session
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
Mutably borrows from an owned value. Read more