pub struct WizardBuilder<T: Wizard> { /* private fields */ }Expand description
Builder for configuring and executing a wizard
Implementations§
Source§impl<T: Wizard> WizardBuilder<T>
impl<T: Wizard> WizardBuilder<T>
Sourcepub fn with_defaults(self, defaults: T) -> Self
pub fn with_defaults(self, defaults: T) -> Self
Set default values for the wizard
Examples found in repository?
More 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}Sourcepub fn with_backend<B: InterviewBackend + 'static>(self, backend: B) -> Self
pub fn with_backend<B: InterviewBackend + 'static>(self, backend: B) -> Self
Set a custom backend
Trait Implementations§
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> 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