use crate::field::FieldTrait;
use crate::input::read_multiselect;
use std::fmt::Debug;
use std::str::FromStr;
#[derive(Debug)]
pub struct MultiselectField<T> {
pub prompt: String,
pub options: Vec<(T, String)>,
pub value: Vec<T>,
pub limit: Option<usize>,
}
impl<T> FieldTrait for MultiselectField<T>
where
T: 'static + Clone + PartialEq + Debug + FromStr,
T::Err: Debug,
{
fn fill(&mut self) -> Result<(), String> {
self.value = read_multiselect(&self.prompt, &self.options, self.limit)?;
Ok(())
}
fn as_any(&self) -> &dyn std::any::Any {
self
}
fn get_value(&self) -> Result<String, String> {
Ok(format!("{:?}", self.value))
}
}