use crate::Backend; use crate::ValueBuilder; pub struct DialoguerBackend; #[derive(Debug, thiserror::Error)] pub enum DialoguerBackendError { #[error("")] Io(#[from] std::io::Error), } impl Backend for DialoguerBackend { type Error = DialoguerBackendError; fn bool_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn u8_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn u16_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn u32_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn u64_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn u128_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn i8_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn i16_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn i32_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn i64_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn i128_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn usize_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn isize_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn f32_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn f64_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn char_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } fn string_builder(&self) -> Box> { Box::new(DialoguerValueBuilder::(std::marker::PhantomData)) } } pub struct DialoguerValueBuilder(std::marker::PhantomData); impl ValueBuilder for DialoguerValueBuilder where T: std::str::FromStr + Clone + std::fmt::Display, T::Err: std::fmt::Display + std::fmt::Debug, { type Output = T; type Error = DialoguerBackendError; fn build_value(&self, question: &str) -> Result { dialoguer::Input::::new() .with_prompt(question) .interact_text() .map_err(DialoguerBackendError::from) } }