pub struct Select<T: Display> {
pub title: String,
pub theme: Theme,
pub description: String,
pub options: Vec<DemandOption<T>>,
pub filterable: bool,
/* private fields */
}Expand description
Select multiple options from a list
Example
use demand::{DemandOption, Select};
let ms = Select::new("Toppings")
.description("Select your topping")
.filterable(true)
.option(DemandOption::new("Lettuce"))
.option(DemandOption::new("Tomatoes"))
.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"));
let topping = ms.run().expect("error running multi select");Fields§
§title: StringThe title of the selector
theme: ThemeThe colors/style of the selector
description: StringA description to display above the selector
options: Vec<DemandOption<T>>The options which can be selected
filterable: boolWhether the selector can be filtered with a query
Implementations§
source§impl<T: Display> Select<T>
impl<T: Display> Select<T>
sourcepub fn new<S: Into<String>>(title: S) -> Self
pub fn new<S: Into<String>>(title: S) -> Self
Create a new select with the given title
Examples found in repository?
examples/select.rs (line 4)
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");
}sourcepub fn description(self, description: &str) -> Self
pub fn description(self, description: &str) -> Self
Set the description of the selector
Examples found in repository?
examples/select.rs (line 5)
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");
}sourcepub fn option(self, option: DemandOption<T>) -> Self
pub fn option(self, option: DemandOption<T>) -> Self
Add an option to the selector
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");
}sourcepub fn filterable(self, filterable: bool) -> Self
pub fn filterable(self, filterable: bool) -> Self
Set whether the selector can be filtered with a query
Examples found in repository?
examples/select.rs (line 6)
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");
}sourcepub fn run(self) -> Result<T>
pub fn run(self) -> Result<T>
Displays the selector to the user and returns their selected options
Examples found in repository?
examples/select.rs (line 14)
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");
}Auto Trait Implementations§
impl<T> RefUnwindSafe for Select<T>where
T: RefUnwindSafe,
impl<T> Send for Select<T>where
T: Send,
impl<T> Sync for Select<T>where
T: Sync,
impl<T> Unpin for Select<T>where
T: Unpin,
impl<T> UnwindSafe for Select<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