From 3996673b3cd198c7e80bfa51d13b2b771657d32a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 24 Apr 2021 17:28:20 +0200 Subject: Add example for config object Signed-off-by: Matthias Beyer --- examples/config.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/config.rs diff --git a/examples/config.rs b/examples/config.rs new file mode 100644 index 0000000..a91aaee --- /dev/null +++ b/examples/config.rs @@ -0,0 +1,40 @@ +use interactive_object_builder::*; +use interactive_object_builder::dialoguer::DialoguerBackend; + +#[derive(Debug)] +pub struct Configuration { + verbose: bool, + values: Vec, +} + +impl BuildableCollection for Configuration { + fn builder(_backend: B) -> Box> + where B: Backend + { + Box::new(ConfigStructBuilder) + } +} + +pub struct ConfigStructBuilder; +impl CollectionBuilder for ConfigStructBuilder { + type Output = Configuration; + + fn build_collection(&self, value_desc: &str) -> Result { + println!("Building {}", value_desc); + + let verbose = bool::builder(DialoguerBackend).build_value("Be verbose?")?; + let values = Vec::::builder(DialoguerBackend).build_collection("List of values")?; + + Ok(Configuration { + verbose, + values, + }) + } +} + +fn main() -> Result<()> { + let c = Configuration::builder(DialoguerBackend).build_collection("config")?; + dbg!(c); + Ok(()) +} + -- cgit v1.2.3