Struct demand::DemandOption
source · pub struct DemandOption<T: Display> {
pub item: T,
pub label: String,
pub selected: bool,
/* private fields */
}Expand description
An individual option in a select or multi-select.
Fields§
§item: TThe item this option represents.
label: StringDisplay label for this option.
selected: boolWhether this option is initially selected.
Implementations§
source§impl<T: Display> DemandOption<T>
impl<T: Display> DemandOption<T>
sourcepub fn new(item: T) -> Self
pub fn new(item: T) -> Self
Create a new option with the given key.
Examples found in repository?
examples/select.rs (line 7)
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() {
let ms = Select::new("Toppings")
.description("Select your toppings")
.filterable(true)
.option(DemandOption::new("Lettuce").selected(true))
.option(DemandOption::new("Tomatoes").selected(true))
.option(DemandOption::new("Charm Sauce"))
.option(DemandOption::new("Jalapenos").label("Jalapeños"))
.option(DemandOption::new("Cheese"))
.option(DemandOption::new("Vegan Cheese"))
.option(DemandOption::new("Nutella"));
ms.run().expect("error running multi select");
}More examples
examples/multiselect.rs (line 9)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
let ms = MultiSelect::new("Toppings")
.description("Select your toppings")
.min(1)
.max(4)
.filterable(true)
.option(DemandOption::new("Lettuce").selected(true))
.option(DemandOption::new("Tomatoes").selected(true))
.option(DemandOption::new("Charm Sauce"))
.option(DemandOption::new("Jalapenos").label("Jalapeños"))
.option(DemandOption::new("Cheese"))
.option(DemandOption::new("Vegan Cheese"))
.option(DemandOption::new("Nutella"));
ms.run().expect("error running multi select");
}sourcepub fn label(self, name: &str) -> Self
pub fn label(self, name: &str) -> Self
Set the display label for this option.
Examples found in repository?
examples/select.rs (line 10)
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() {
let ms = Select::new("Toppings")
.description("Select your toppings")
.filterable(true)
.option(DemandOption::new("Lettuce").selected(true))
.option(DemandOption::new("Tomatoes").selected(true))
.option(DemandOption::new("Charm Sauce"))
.option(DemandOption::new("Jalapenos").label("Jalapeños"))
.option(DemandOption::new("Cheese"))
.option(DemandOption::new("Vegan Cheese"))
.option(DemandOption::new("Nutella"));
ms.run().expect("error running multi select");
}More examples
examples/multiselect.rs (line 12)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
let ms = MultiSelect::new("Toppings")
.description("Select your toppings")
.min(1)
.max(4)
.filterable(true)
.option(DemandOption::new("Lettuce").selected(true))
.option(DemandOption::new("Tomatoes").selected(true))
.option(DemandOption::new("Charm Sauce"))
.option(DemandOption::new("Jalapenos").label("Jalapeños"))
.option(DemandOption::new("Cheese"))
.option(DemandOption::new("Vegan Cheese"))
.option(DemandOption::new("Nutella"));
ms.run().expect("error running multi select");
}sourcepub fn selected(self, selected: bool) -> Self
pub fn selected(self, selected: bool) -> Self
Set whether this option is initially selected.
Examples found in repository?
examples/select.rs (line 7)
3 4 5 6 7 8 9 10 11 12 13 14 15
fn main() {
let ms = Select::new("Toppings")
.description("Select your toppings")
.filterable(true)
.option(DemandOption::new("Lettuce").selected(true))
.option(DemandOption::new("Tomatoes").selected(true))
.option(DemandOption::new("Charm Sauce"))
.option(DemandOption::new("Jalapenos").label("Jalapeños"))
.option(DemandOption::new("Cheese"))
.option(DemandOption::new("Vegan Cheese"))
.option(DemandOption::new("Nutella"));
ms.run().expect("error running multi select");
}More examples
examples/multiselect.rs (line 9)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
let ms = MultiSelect::new("Toppings")
.description("Select your toppings")
.min(1)
.max(4)
.filterable(true)
.option(DemandOption::new("Lettuce").selected(true))
.option(DemandOption::new("Tomatoes").selected(true))
.option(DemandOption::new("Charm Sauce"))
.option(DemandOption::new("Jalapenos").label("Jalapeños"))
.option(DemandOption::new("Cheese"))
.option(DemandOption::new("Vegan Cheese"))
.option(DemandOption::new("Nutella"));
ms.run().expect("error running multi select");
}Trait Implementations§
source§impl<T: Clone + Display> Clone for DemandOption<T>
impl<T: Clone + Display> Clone for DemandOption<T>
source§fn clone(&self) -> DemandOption<T>
fn clone(&self) -> DemandOption<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: Display> PartialEq for DemandOption<T>
impl<T: Display> PartialEq for DemandOption<T>
impl<T: Display> Eq for DemandOption<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for DemandOption<T>where
T: RefUnwindSafe,
impl<T> Send for DemandOption<T>where
T: Send,
impl<T> Sync for DemandOption<T>where
T: Sync,
impl<T> Unpin for DemandOption<T>where
T: Unpin,
impl<T> UnwindSafe for DemandOption<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