pub struct Selector<I, T>where
I: IntoIterator<Item = T>,{ /* private fields */ }Expand description
Wraps a variable amount of choices and provides methods that guarantee selection from those choices.
Implementations§
Source§impl<I, T> Selector<I, T>where
I: IntoIterator<Item = T>,
impl<I, T> Selector<I, T>where
I: IntoIterator<Item = T>,
Sourcepub fn with<const K: usize, C>(self, chooser: C) -> [T; K]
pub fn with<const K: usize, C>(self, chooser: C) -> [T; K]
The function chooser is used to choose from our provided
choices by returning a K-selection of it. The values of these choices are then
returned by the function.
use choose_from::select_from;
let choices = vec!["Hi", "how", "are ya?"];
let chosen = select_from(choices).with(|mut choices| {
// the provided choices allow inspection of the values
let third = choices.pop().unwrap();
assert_eq!(*third, "are ya?");
// ignore 2nd
choices.pop();
let first = choices.pop().unwrap();
// this is our selection
[first, third]
});
assert_eq!(chosen, ["Hi", "are ya?"]);Sourcepub fn any_with<C>(self, chooser: C) -> Vec<T>
pub fn any_with<C>(self, chooser: C) -> Vec<T>
Like with, but for returning any number of chosen values. Use this when you want to ensure some values come from the choices, but the amount of chosen values returned doesn’t matter.
use choose_from::select_from;
let choices = vec!["Hi", "how", "are ya?"];
let chosen = select_from(choices).any_with(|choices| {
choices.into_iter().step_by(2).collect()
});
assert_eq!(chosen, ["Hi", "are ya?"]);Trait Implementations§
Source§impl<I, T: PartialEq> PartialEq for Selector<I, T>where
I: IntoIterator<Item = T> + PartialEq,
impl<I, T: PartialEq> PartialEq for Selector<I, T>where
I: IntoIterator<Item = T> + PartialEq,
impl<I, T: Eq> Eq for Selector<I, T>where
I: IntoIterator<Item = T> + Eq,
impl<I, T> StructuralPartialEq for Selector<I, T>where
I: IntoIterator<Item = T>,
Auto Trait Implementations§
impl<I, T> Freeze for Selector<I, T>where
I: Freeze,
impl<I, T> RefUnwindSafe for Selector<I, T>where
I: RefUnwindSafe,
impl<I, T> Send for Selector<I, T>where
I: Send,
impl<I, T> Sync for Selector<I, T>where
I: Sync,
impl<I, T> Unpin for Selector<I, T>where
I: Unpin,
impl<I, T> UnwindSafe for Selector<I, T>where
I: 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