pub struct SelectorFixed<const N: usize, T> { /* private fields */ }Expand description
Wraps a fixed number of choices and provides methods that guarantee selection from those choices, where N is the possible number of choices set at compile time.
Implementations§
Source§impl<const N: usize, T> SelectorFixed<N, T>
impl<const N: usize, T> SelectorFixed<N, 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 them. The values of these choices are then
returned by the function.
use choose_from::select_from_fixed;
let choices = ["Hi", "how", "are ya?"];
let chosen = select_from_fixed(choices).with(|[first, second, third]| {
// the provided choices allow inspection of the values
assert_eq!(*first, "Hi");
// 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_fixed;
let choices = ["Hi", "how", "are ya?"];
let chosen = select_from_fixed(choices).any_with(|choices| {
choices.into_iter().step_by(2).collect()
});
assert_eq!(chosen, ["Hi", "are ya?"]);Trait Implementations§
impl<const N: usize, T: Eq> Eq for SelectorFixed<N, T>
impl<const N: usize, T> StructuralPartialEq for SelectorFixed<N, T>
Auto Trait Implementations§
impl<const N: usize, T> Freeze for SelectorFixed<N, T>where
T: Freeze,
impl<const N: usize, T> RefUnwindSafe for SelectorFixed<N, T>where
T: RefUnwindSafe,
impl<const N: usize, T> Send for SelectorFixed<N, T>where
T: Send,
impl<const N: usize, T> Sync for SelectorFixed<N, T>where
T: Sync,
impl<const N: usize, T> Unpin for SelectorFixed<N, T>where
T: Unpin,
impl<const N: usize, T> UnwindSafe for SelectorFixed<N, 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