blob: 25610ff31182a3701b0dbf0fc0aebe4a97aba7dd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
use interactive_object_builder::*;
use interactive_object_builder::dialoguer::DialoguerBackend;
#[derive(Debug)]
pub struct Configuration {
verbose: bool,
values: Vec<u8>,
}
impl BuildableCollection for Configuration {
fn builder<B>(backend: B) -> Box<dyn CollectionBuilder<Output = Self>>
where B: 'static + Backend
{
Box::new(ConfigStructBuilder(backend))
}
}
pub struct ConfigStructBuilder<B: 'static + Backend>(B);
impl<B: 'static + Backend> CollectionBuilder for ConfigStructBuilder<B> {
type Output = Configuration;
fn build_collection(&self, value_desc: &str) -> Result<Self::Output> {
println!("Building {}", value_desc);
let verbose = bool::builder(self.0).build_value("Be verbose?", Some(&false))?;
let values = Vec::<u8>::builder(self.0).build_collection("List of values")?;
Ok(Configuration {
verbose,
values,
})
}
}
fn main() -> Result<()> {
let c = Configuration::builder(DialoguerBackend).build_collection("config")?;
dbg!(c);
Ok(())
}
|