Wizard

Trait Wizard 

Source
pub trait Wizard: Sized {
    // Required methods
    fn interview() -> Interview;
    fn interview_with_suggestions(&self) -> Interview;
    fn from_answers(answers: &Answers) -> Result<Self, BackendError>;
    fn validate_field(
        field: &str,
        value: &str,
        answers: &Answers,
    ) -> Result<(), String>;

    // Provided method
    fn wizard_builder() -> WizardBuilder<Self> { ... }
}

Required Methods§

Source

fn interview() -> Interview

Get the interview structure for this type

Source

fn interview_with_suggestions(&self) -> Interview

Get the interview structure with suggested values from this instance

Source

fn from_answers(answers: &Answers) -> Result<Self, BackendError>

Build this type from collected answers

Source

fn validate_field( field: &str, value: &str, answers: &Answers, ) -> Result<(), String>

Validate a field value This is called by backends during execution to validate user input

Provided Methods§

Source

fn wizard_builder() -> WizardBuilder<Self>

Create a builder for this wizard

Examples found in repository?
examples/basic/nested_structs.rs (line 43)
42fn main() {
43    let user = User::wizard_builder().build().unwrap();
44    println!("{user:#?}");
45}
More examples
Hide additional examples
examples/advanced/deeply_nested.rs (line 40)
39fn main() {
40    let event = Event::wizard_builder().build().unwrap();
41    println!("{event:#?}");
42}
examples/advanced/nested_enum_payment.rs (line 40)
39fn main() {
40    let order = Order::wizard_builder().build().unwrap();
41    println!("{:#?}", order);
42}
examples/features/validation.rs (line 66)
65fn main() {
66    let config = ServerConfig::wizard_builder().build().unwrap();
67    println!("{config:#?}");
68}
examples/features/password_masking.rs (line 15)
14fn main() {
15    let form = LoginForm::wizard_builder().build().unwrap();
16    println!("LoginForm: {form:#?}");
17}
examples/basic/pathbuf.rs (line 11)
10fn main() {
11    let config = FileConfig::wizard_builder().build().unwrap();
12    println!("  Input:  {:?}", config.path);
13}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§