builder_api/
builder_api.rs

1use derive_wizard::Wizard;
2
3#[derive(Debug, Clone, Wizard)]
4struct ServerConfig {
5    #[prompt("Server host:")]
6    host: String,
7
8    #[prompt("Server port:")]
9    #[min(1024)]
10    #[max(65535)]
11    port: i32,
12
13    #[prompt("Enable SSL:")]
14    ssl: bool,
15}
16
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}