Struct stepflow::Session [−][src]
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
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]
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 Step
s
pub fn step_store_mut(&mut self) -> &mut ObjectStore<Step, StepId>
[src]
Mutable store for Step
s
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]
&self
) -> &ObjectStore<Box<dyn Action + 'static + Sync + Send, Global>, ActionId>
Store for Action
s
pub fn action_store_mut(
&mut self
) -> &mut ObjectStore<Box<dyn Action + 'static + Sync + Send, Global>, ActionId>
[src]
&mut self
) -> &mut ObjectStore<Box<dyn Action + 'static + Sync + Send, Global>, ActionId>
pub fn var_store(
&self
) -> &ObjectStore<Box<dyn Var + 'static + Sync + Send, Global>, VarId>
[src]
&self
) -> &ObjectStore<Box<dyn Var + 'static + Sync + Send, Global>, VarId>
Store for Var
s
pub fn var_store_mut(
&mut self
) -> &mut ObjectStore<Box<dyn Var + 'static + Sync + Send, Global>, VarId>
[src]
&mut self
) -> &mut ObjectStore<Box<dyn Var + 'static + Sync + Send, Global>, VarId>
Mutable store for Var
s
pub fn set_action_for_step(
&mut self,
action_id: ActionId,
step_id: Option<&StepId>
) -> Result<(), Error>
[src]
&mut self,
action_id: ActionId,
step_id: Option<&StepId>
) -> Result<(), Error>
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]
&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 !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]
T: 'static + ?Sized,
impl<T> AsAny for T where
T: Any,
[src]
T: Any,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,