use interactive_object_builder::*; #[derive(Copy, Clone)] pub struct DummyBackend; impl Backend for DummyBackend { fn bool_builder(&self) -> Box> { Box::new(BoolValBuilder) } fn u8_builder(&self) -> Box> { Box::new(U8ValueBuilder) } fn u16_builder(&self) -> Box> { unimplemented!() } fn u32_builder(&self) -> Box> { unimplemented!() } fn u64_builder(&self) -> Box> { unimplemented!() } fn u128_builder(&self) -> Box> { unimplemented!() } fn i8_builder(&self) -> Box> { unimplemented!() } fn i16_builder(&self) -> Box> { unimplemented!() } fn i32_builder(&self) -> Box> { unimplemented!() } fn i64_builder(&self) -> Box> { unimplemented!() } fn i128_builder(&self) -> Box> { unimplemented!() } fn usize_builder(&self) -> Box> { unimplemented!() } fn isize_builder(&self) -> Box> { unimplemented!() } fn f32_builder(&self) -> Box> { unimplemented!() } fn f64_builder(&self) -> Box> { unimplemented!() } fn char_builder(&self) -> Box> { unimplemented!() } fn string_builder(&self) -> Box> { unimplemented!() } fn option_builder(&self) -> Box>> { unimplemented!() } fn vec_builder(&self) -> Box>> where T: 'static + BuildableValue { Box::new(VecBuilder::(std::marker::PhantomData)) } fn struct_builder(&self) -> Box> where T: 'static + BuildableCollection { Box::new(StructBuilder::(std::marker::PhantomData)) } } pub struct BoolValBuilder; impl ValueBuilder for BoolValBuilder { type Output = bool; fn build_value(&self, _question: &str, _default: Option<&Self::Output>) -> Result { Ok(true) } } pub struct U8ValueBuilder; impl ValueBuilder for U8ValueBuilder { type Output = u8; fn build_value(&self, _question: &str, _default: Option<&Self::Output>) -> Result { Ok(42) } } pub struct VecBuilder(std::marker::PhantomData); impl CollectionBuilder for VecBuilder { type Output = Vec; fn build_collection(&self, value_desc: &str) -> Result { let mut buf = vec![]; loop { let v: T = T::builder(DummyBackend).build_value(value_desc, None)?; buf.push(v); if buf.len() == 3 { break } } Ok(buf) } } pub struct StructBuilder(std::marker::PhantomData); impl CollectionBuilder for StructBuilder { type Output = T; fn build_collection(&self, value_desc: &str) -> Result { T::builder(DummyBackend).build_collection(value_desc) } }