Struct smart_read::list_constraints::OptionWithData
source · pub struct OptionWithData<T: Clone + PartialEq> {
pub display_name: String,
pub data: T,
}Expand description
Allows you to add more data to an option
Example:
// example data
let mut colors = vec!("Red", "green", "Blue");
// prepare options, only capitalized colors can be removed
let choosable_colors =
colors.iter().enumerate()
.filter_map(|(i, color_name)| {
let first_char = color_name.chars().next()?;
if first_char.is_lowercase() {return None;}
Some(OptionWithData {name: color_name.to_string(), data: i})
})
.collect::<Vec<_>>();
// prompt
let OptionWithData {name: _, data: index_to_remove} = prompt!("Choose a color to remove: "; choosable_colors);
colors.remove(index_to_remove);Fields§
§display_name: StringWhat’s shown to the user
data: TWhat isn’t shown to the user
Trait Implementations§
source§impl<T: Clone + Clone + PartialEq> Clone for OptionWithData<T>
impl<T: Clone + Clone + PartialEq> Clone for OptionWithData<T>
source§fn clone(&self) -> OptionWithData<T>
fn clone(&self) -> OptionWithData<T>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl<T: PartialEq + Clone + PartialEq> PartialEq for OptionWithData<T>
impl<T: PartialEq + Clone + PartialEq> PartialEq for OptionWithData<T>
source§fn eq(&self, other: &OptionWithData<T>) -> bool
fn eq(&self, other: &OptionWithData<T>) -> bool
This method tests for
self and other values to be equal, and is used
by ==.impl<T: Clone + PartialEq> StructuralPartialEq for OptionWithData<T>
Auto Trait Implementations§
impl<T> Freeze for OptionWithData<T>where
T: Freeze,
impl<T> RefUnwindSafe for OptionWithData<T>where
T: RefUnwindSafe,
impl<T> Send for OptionWithData<T>where
T: Send,
impl<T> Sync for OptionWithData<T>where
T: Sync,
impl<T> Unpin for OptionWithData<T>where
T: Unpin,
impl<T> UnwindSafe for OptionWithData<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more