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_suggestions(self, suggestions: T) -> Self
pub fn with_suggestions(self, suggestions: T) -> Self
Set suggested values for the wizard
Examples found in repository?
examples/builders/builder_comprehensive.rs (line 124)
115fn run_suggestions_demo() {
116 println!("\n--- Demo with Suggestions ---");
117 let suggestions = UserProfile {
118 name: "John Doe".to_string(),
119 age: 30,
120 email: "john@example.com".to_string(),
121 subscribe: true,
122 };
123 let profile = UserProfile::wizard_builder()
124 .with_suggestions(suggestions)
125 .build()
126 .unwrap();
127 println!("Profile: {:#?}", profile);
128}More examples
examples/features/suggestions.rs (line 24)
16fn main() {
17 println!("=== Creating a new user profile ===");
18 let profile = UserProfile::wizard_builder().build().unwrap();
19 println!("Created profile: {profile:#?}");
20
21 println!("=== Editing the existing profile ===");
22 println!("The current values will be pre-filled as suggestions.");
23 let updated_profile = UserProfile::wizard_builder()
24 .with_suggestions(profile)
25 .build()
26 .unwrap();
27 println!("Updated profile: {updated_profile:#?}");
28}examples/builders/builder_api.rs (line 45)
17fn main() {
18 println!("=== Builder API Demo ===");
19
20 // Example 1: Simple builder with default backend
21 println!("Example 1: Using default backend");
22 let config1 = ServerConfig::wizard_builder().build().unwrap();
23 println!("Config: {:#?}", 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::wizard_builder()
31 .with_backend(backend)
32 .build()
33 .unwrap();
34 println!("Config: {:#?}", config2);
35 }
36
37 // Example 3: Builder with suggestions
38 println!("Example 3: Using suggestions (re-prompting with existing values)");
39 let suggestions = ServerConfig {
40 host: "localhost".to_string(),
41 port: 8080,
42 ssl: true,
43 };
44 let config3 = ServerConfig::wizard_builder()
45 .with_suggestions(suggestions)
46 .build()
47 .unwrap();
48 println!("Config: {:#?}", config3);
49}Sourcepub fn suggest_field(
self,
field: impl Into<FieldPath>,
value: impl Into<SuggestedAnswer>,
) -> Self
pub fn suggest_field( self, field: impl Into<FieldPath>, value: impl Into<SuggestedAnswer>, ) -> Self
Suggest a specific field value. The question will still be asked but with a pre-filled default.
For nested fields, use the field! macro.
Sourcepub fn assume_field(
self,
field: impl Into<FieldPath>,
value: impl Into<AssumedAnswer>,
) -> Self
pub fn assume_field( self, field: impl Into<FieldPath>, value: impl Into<AssumedAnswer>, ) -> Self
Assume a specific field value. The question for this field will be skipped.
For nested fields, use the field! macro.
Examples found in repository?
examples/features/assumptions.rs (line 34)
26fn main() {
27 println!("=== Deployment Configuration Tool ===");
28
29 // Scenario 1: Partial assumptions - the most common use case
30 println!("--- Scenario 1: Partial Assumptions (Recommended) ---");
31 println!("We'll assume some security-critical values but ask about others.");
32
33 let config = DeploymentConfig::wizard_builder()
34 .assume_field("environment", "production".to_string()) // Fixed: production
35 .assume_field("debug", false) // Fixed: no debug in prod
36 .assume_field("port", 443) // Fixed: HTTPS port
37 .build()
38 .unwrap(); // Will only ask about 'app_name' and 'database_url'
39
40 println!("=== Configuration (with partial assumptions) ===");
41 println!("{:#?}", config);
42 println!("Notice: Only asked about app_name and database_url!");
43 println!("The fields 'environment', 'debug', and 'port' were assumed.");
44
45 // Scenario 2: Full assumptions - for batch processing
46 println!("--- Scenario 2: Full Assumptions (for automation) ---");
47 println!("Using a complete template - no questions will be asked.");
48
49 let batch_config = DeploymentConfig::wizard_builder()
50 .assume_field("app_name", "batch-processor".to_string())
51 .assume_field("environment", "production".to_string())
52 .assume_field("port", 8080)
53 .assume_field("debug", false)
54 .assume_field(
55 "database_url",
56 "postgresql://prod-db:5432/batch".to_string(),
57 )
58 .build()
59 .unwrap();
60
61 println!("=== Batch Configuration (all assumed, no questions) ===");
62 println!("{:#?}", batch_config);
63
64 println!("--- Summary ---");
65 println!("Partial assumptions: Fix some fields, ask about others");
66 println!("Full assumptions: Fix all fields, no user interaction");
67 println!("Suggestions: Pre-fill values, but still ask all questions");
68}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
Examples found in repository?
examples/backends/requestty_multi_select.rs (line 44)
41fn main() {
42 let backend = derive_wizard::RequesttyBackend;
43 let order = PizzaOrder::wizard_builder()
44 .with_backend(backend)
45 .build()
46 .unwrap();
47
48 println!("\n📋 Order Summary");
49 println!("────────────────");
50 println!("Name: {}", order.name);
51 println!("Size: {:?}", order.size);
52 println!("Toppings: {:?}", order.toppings);
53}Sourcepub fn build(self) -> Result<T, BackendError>
pub fn build(self) -> Result<T, BackendError>
Execute the wizard and return the result
Examples found in repository?
More examples
Additional examples can be found in:
- examples/basic/enum_transport.rs
- examples/basic/simple_struct.rs
- examples/features/prelude_epilogue.rs
- examples/features/nested_validation.rs
- examples/features/multiline.rs
- examples/backends/requestty_multi_select.rs
- examples/features/suggestions.rs
- examples/builders/builder_comprehensive.rs
- examples/showcase.rs
- examples/builders/builder_api.rs
- examples/features/assumptions.rs
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