builder_comprehensive/
builder_comprehensive.rs1use derive_wizard::Wizard;
2
3#[derive(Debug, Clone, Wizard)]
4struct UserProfile {
5 #[prompt("Enter your name:")]
6 name: String,
7
8 #[prompt("Enter your age:")]
9 #[min(0)]
10 #[max(150)]
11 age: i32,
12
13 #[prompt("Enter your email:")]
14 email: String,
15
16 #[prompt("Subscribe to newsletter:")]
17 subscribe: bool,
18}
19
20#[derive(Debug, Clone, Wizard)]
22enum BackendChoice {
23 #[cfg(feature = "requestty-backend")]
25 Requestty,
26
27 #[cfg(feature = "dialoguer-backend")]
29 Dialoguer,
30
31 #[cfg(feature = "ratatui-backend")]
33 Ratatui,
34
35 #[cfg(feature = "egui-backend")]
37 Egui,
38
39 #[cfg(feature = "requestty-backend")]
41 Suggestions,
42}
43
44fn main() {
45 println!("=== Comprehensive Builder API Demo ===\n");
46
47 let choice = BackendChoice::wizard_builder().build().unwrap();
49
50 match choice {
51 #[cfg(feature = "requestty-backend")]
52 BackendChoice::Requestty => run_requestty_demo(),
53
54 #[cfg(feature = "dialoguer-backend")]
55 BackendChoice::Dialoguer => run_dialoguer_demo(),
56
57 #[cfg(feature = "ratatui-backend")]
58 BackendChoice::Ratatui => run_ratatui_demo(),
59
60 #[cfg(feature = "egui-backend")]
61 BackendChoice::Egui => run_egui_demo(),
62
63 #[cfg(feature = "requestty-backend")]
64 BackendChoice::Suggestions => run_suggestions_demo(),
65 }
66
67 println!("\n=== Demo Complete ===");
68}
69
70#[cfg(feature = "requestty-backend")]
71fn run_requestty_demo() {
72 println!("\n--- Requestty Backend Demo ---");
73 let profile = UserProfile::wizard_builder().build().unwrap();
74 println!("Profile: {:#?}", profile);
75}
76
77#[cfg(feature = "dialoguer-backend")]
78fn run_dialoguer_demo() {
79 println!("\n--- Dialoguer Backend Demo ---");
80 let backend = derive_wizard::DialoguerBackend::new();
81 let profile = UserProfile::wizard_builder()
82 .with_backend(backend)
83 .build()
84 .unwrap();
85 println!("Profile: {:#?}", profile);
86}
87
88#[cfg(feature = "ratatui-backend")]
89fn run_ratatui_demo() {
90 println!("\n--- Ratatui Backend Demo ---");
91 let backend = derive_wizard::RatatuiBackend::new().with_title("User Profile");
92
93 let profile = UserProfile::wizard_builder()
94 .with_backend(backend)
95 .build()
96 .unwrap();
97 println!("Profile: {:#?}", profile);
98}
99
100#[cfg(feature = "egui-backend")]
101fn run_egui_demo() {
102 println!("\n--- Egui Backend Demo ---");
103 let backend = derive_wizard::EguiBackend::new()
104 .with_title("User Profile")
105 .with_window_size([450.0, 350.0]);
106
107 let profile = UserProfile::wizard_builder()
108 .with_backend(backend)
109 .build()
110 .unwrap();
111 println!("Profile: {:#?}", profile);
112}
113
114#[cfg(feature = "requestty-backend")]
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}