summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-04-24 17:28:20 +0200
committerMatthias Beyer <mail@beyermatthias.de>2021-04-24 17:28:20 +0200
commit3996673b3cd198c7e80bfa51d13b2b771657d32a (patch)
tree9010292e0772694a380152c9425a938632503593
parent9946502098742151d54acf3133af17c67429204e (diff)
Add example for config object
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--examples/config.rs40
1 files changed, 40 insertions, 0 deletions
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<u8>,
+}
+
+impl BuildableCollection for Configuration {
+ fn builder<B>(_backend: B) -> Box<dyn CollectionBuilder<Output = Self>>
+ where B: Backend
+ {
+ Box::new(ConfigStructBuilder)
+ }
+}
+
+pub struct ConfigStructBuilder;
+impl CollectionBuilder for ConfigStructBuilder {
+ type Output = Configuration;
+
+ fn build_collection(&self, value_desc: &str) -> Result<Self::Output> {
+ println!("Building {}", value_desc);
+
+ let verbose = bool::builder(DialoguerBackend).build_value("Be verbose?")?;
+ let values = Vec::<u8>::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(())
+}
+