SelectorFixed

Struct SelectorFixed 

Source
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>

Source

pub fn with<const K: usize, C>(self, chooser: C) -> [T; K]
where C: FnOnce([Choice<'_, T>; N]) -> [Choice<'_, 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?"]);
Source

pub fn any_with<C>(self, chooser: C) -> Vec<T>
where C: FnOnce([Choice<'_, T>; N]) -> Vec<Choice<'_, 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§

Source§

impl<const N: usize, T: Debug> Debug for SelectorFixed<N, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const N: usize, T: Hash> Hash for SelectorFixed<N, T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<const N: usize, T: PartialEq> PartialEq for SelectorFixed<N, T>

Source§

fn eq(&self, other: &SelectorFixed<N, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const N: usize, T: Eq> Eq for SelectorFixed<N, T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.