WizardBuilder

Struct WizardBuilder 

Source
pub struct WizardBuilder<T: Wizard> { /* private fields */ }
Expand description

Builder for configuring and executing a wizard

Implementations§

Source§

impl<T: Wizard> WizardBuilder<T>

Source

pub fn new() -> Self

Create a new wizard builder

Source

pub fn with_defaults(self, defaults: T) -> Self

Set default values for the wizard

Examples found in repository?
examples/defaults_demo.rs (line 23)
16fn main() {
17    println!("=== Creating a new user profile ===");
18    let profile = UserProfile::wizard_builder().build();
19    println!("Created profile: {profile:#?}\n");
20
21    println!("=== Editing the existing profile ===");
22    println!("The current values will be pre-filled as defaults.");
23    let updated_profile = UserProfile::wizard_builder().with_defaults(profile).build();
24    println!("Updated profile: {updated_profile:#?}");
25}
More examples
Hide additional examples
examples/builder_api.rs (line 42)
17fn main() {
18    println!("=== Builder API Demo ===\n");
19
20    // Example 1: Simple builder with default backend
21    println!("Example 1: Using default backend");
22    let config1 = ServerConfig::wizard_builder().build();
23    println!("Config: {:#?}\n", config1);
24
25    // Example 2: Builder with custom backend (dialoguer)
26    #[cfg(feature = "dialoguer-backend")]
27    {
28        println!("Example 2: Using dialoguer backend");
29        let backend = derive_wizard::DialoguerBackend::new();
30        let config2 = ServerConfig::builder().with_backend(backend).build();
31        println!("Config: {:#?}\n", config2);
32    }
33
34    // Example 3: Builder with defaults
35    println!("Example 3: Using defaults (re-prompting with existing values)");
36    let defaults = ServerConfig {
37        host: "localhost".to_string(),
38        port: 8080,
39        ssl: true,
40    };
41    let config3 = ServerConfig::wizard_builder()
42        .with_defaults(defaults)
43        .build();
44    println!("Config: {:#?}\n", config3);
45}
examples/builder_comprehensive.rs (line 64)
20fn main() {
21    println!("=== Comprehensive Builder API Demo ===\n");
22
23    // Example 1: Default usage (uses requestty backend by default)
24    #[cfg(feature = "requestty-backend")]
25    {
26        println!("--- Example 1: Default Builder (Requestty) ---");
27        let profile1 = UserProfile::wizard_builder().build();
28        println!("Profile: {:#?}\n", profile1);
29    }
30
31    // Example 2: With dialoguer backend
32    #[cfg(feature = "dialoguer-backend")]
33    {
34        println!("--- Example 2: Builder with Dialoguer Backend ---");
35        let backend = derive_wizard::DialoguerBackend::new();
36        let profile2 = UserProfile::builder().with_backend(backend).build();
37        println!("Profile: {:#?}\n", profile2);
38    }
39
40    // Example 3: With egui backend
41    #[cfg(feature = "egui-backend")]
42    {
43        println!("--- Example 3: Builder with Egui Backend ---");
44        let backend = derive_wizard::EguiBackend::new()
45            .with_title("User Profile")
46            .with_window_size([450.0, 350.0]);
47
48        let profile3 = UserProfile::builder().with_backend(backend).build();
49        println!("Profile: {:#?}\n", profile3);
50    }
51
52    // Example 4: With defaults (will be prompted with these as starting values)
53    #[cfg(feature = "requestty-backend")]
54    {
55        println!("--- Example 4: Builder with Default Values ---");
56        let defaults = UserProfile {
57            name: "John Doe".to_string(),
58            age: 30,
59            email: "john@example.com".to_string(),
60            subscribe: true,
61        };
62
63        let profile4 = UserProfile::wizard_builder()
64            .with_defaults(defaults)
65            .build();
66        println!("Profile: {:#?}\n", profile4);
67    }
68
69    // Example 5: Combining defaults with custom backend
70    #[cfg(all(feature = "requestty-backend", feature = "dialoguer-backend"))]
71    {
72        println!("--- Example 5: Builder with Defaults AND Custom Backend ---");
73        let defaults = UserProfile {
74            name: "Jane Smith".to_string(),
75            age: 25,
76            email: "jane@example.com".to_string(),
77            subscribe: false,
78        };
79
80        let backend = derive_wizard::DialoguerBackend::new();
81
82        let profile5 = UserProfile::builder()
83            .with_defaults(defaults)
84            .with_backend(backend)
85            .build();
86        println!("Profile: {:#?}\n", profile5);
87    }
88
89    println!("=== Demo Complete ===");
90}
Source

pub fn with_backend<B: InterviewBackend + 'static>(self, backend: B) -> Self

Set a custom backend

Source

pub fn build(self) -> T

Execute the wizard and return the result

Examples found in repository?
examples/nested_wizard.rs (line 43)
42fn main() {
43    let user = User::wizard_builder().build();
44    println!("{user:#?}");
45}
More examples
Hide additional examples
examples/deeply_nested.rs (line 40)
39fn main() {
40    let event = Event::wizard_builder().build();
41    println!("{event:#?}");
42}
examples/nested_enum_payment.rs (line 40)
39fn main() {
40    let order = Order::wizard_builder().build();
41    println!("{:#?}", order);
42}
examples/validation.rs (line 66)
65fn main() {
66    let config = ServerConfig::wizard_builder().build();
67    println!("{config:#?}");
68}
examples/enum_gender.rs (line 51)
50fn main() {
51    let magic = ShowCase::wizard_builder().build();
52    println!("Config: {magic:#?}");
53}
examples/showcase.rs (line 54)
53fn main() {
54    let magic = ShowCase::wizard_builder().build();
55    println!("Config: {magic:#?}");
56}

Trait Implementations§

Source§

impl<T: Default + Wizard> Default for WizardBuilder<T>

Source§

fn default() -> WizardBuilder<T>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for WizardBuilder<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for WizardBuilder<T>

§

impl<T> !Send for WizardBuilder<T>

§

impl<T> !Sync for WizardBuilder<T>

§

impl<T> Unpin for WizardBuilder<T>
where T: Unpin,

§

impl<T> !UnwindSafe for WizardBuilder<T>

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.