Skip to main content

WizardStep

Struct WizardStep 

Source
pub struct WizardStep {
    pub name: String,
    pub form: Form,
    pub condition: Option<Box<dyn Fn(&HashMap<String, HashMap<String, Value>>) -> bool + Send + Sync>>,
}
Expand description

A single step in the wizard

Fields§

§name: String§form: Form§condition: Option<Box<dyn Fn(&HashMap<String, HashMap<String, Value>>) -> bool + Send + Sync>>

Implementations§

Source§

impl WizardStep

Source

pub fn new(name: String, form: Form) -> Self

Create a new wizard step

§Examples
use reinhardt_forms::{WizardStep, Form};

let form = Form::new();
let step = WizardStep::new("step1".to_string(), form);
assert_eq!(step.name, "step1");
Source

pub fn with_condition<F>(self, condition: F) -> Self
where F: Fn(&HashMap<String, HashMap<String, Value>>) -> bool + Send + Sync + 'static,

Add a condition for when this step should be available

§Examples
use reinhardt_forms::{WizardStep, Form};
use std::collections::HashMap;
use serde_json::json;

let form = Form::new();
let step = WizardStep::new("step2".to_string(), form)
    .with_condition(|data| {
        data.get("step1").map_or(false, |step1_data| {
            step1_data.get("age").and_then(|v| v.as_i64()).map_or(false, |age| age >= 18)
        })
    });
Source

pub fn is_available( &self, session_data: &HashMap<String, HashMap<String, Value>>, ) -> bool

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