[][src]Struct hidden::dispenser::Hand

pub struct Hand<'h, T>(_, _);

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

impl<'h, T: Debug> Debug for Hand<'h, T>[src]

Auto Trait Implementations

impl<'h, T> RefUnwindSafe for Hand<'h, T> where
    T: RefUnwindSafe

impl<'h, T> Send for Hand<'h, T> where
    T: Sync

impl<'h, T> Sync for Hand<'h, T> where
    T: Sync

impl<'h, T> Unpin for Hand<'h, T>

impl<'h, T> UnwindSafe for Hand<'h, T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,