[−][src]Struct hidden::dispenser::Hand
A lock on a slice of choices, with a slice of elements to match them.
Implementations
impl<'h, T> Hand<'h, T>
[src]
pub fn new(choices: Box<[usize]>, elements: &'h [T]) -> Hand<'h, T>
[src]
Creates a new hand from a slice of choices, and a slice of elements.
Slice length equivalence isn't checked.
pub fn choose(&self, idx: usize) -> Option<&T>
[src]
Pick from a series of choices by index, which then picks a corresponding element from the list.
This function uses the internal (frozen) slice of choices to choose an element out of the slice of elements.
With a choice slice of [2,3,1,0,4]
, and an element slice of [A,B,C,D,E]
, picking choice
1
(as an index) would use choice 4
to pick D
.
1 -> [..., 4, ...] -> [..., D, ...]
use hidden::dispenser::Hand; // Note, this is not how you'd go about getting a Hand // Please use a Dispenser instead let choices = Box::from([2,3,1,0,4]); let elements = &['a','b','c','d','e']; let hand = Hand::new(choices, elements); assert_eq!(hand.choose(1).unwrap(), &'d'); // idx 1 -> choice 3 -> element d assert_eq!(hand.choose(2).unwrap(), &'b'); // idx 2 -> choice 1 -> element b
Returns None
if idx
exceeds amount of choices, or if choice can't correspond to
an element in the list.
Returns Some
with a reference to an element if the choosing succeeds.
pub fn len(&self) -> usize
[src]
Returns the amount of choices that this hand has.
Trait Implementations
Auto Trait Implementations
impl<'h, T> RefUnwindSafe for Hand<'h, T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<'h, T> Send for Hand<'h, T> where
T: Sync,
T: Sync,
impl<'h, T> Sync for Hand<'h, T> where
T: Sync,
T: Sync,
impl<'h, T> Unpin for Hand<'h, T>
impl<'h, T> UnwindSafe for Hand<'h, T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,