HandN

Struct HandN 

Source
pub struct HandN<const N: usize>(/* private fields */);
Expand description

Fixed-size hand representation.

Represents exactly N cards. Cards are stored sorted and deduplicated.

Implementations§

Source§

impl<const N: usize> HandN<N>

Source

pub fn from_slice(cs: &[Card]) -> Self

Creates a sorted hand from a slice.

Source

pub fn iter_all<const SD: bool>() -> HandIter<SD, N>

Returns an iterator over all possible N-card hands (card combination)

Source§

impl<const N: usize> HandN<N>

Source

pub fn new_iso_with_mapping(cards: &[Card], mapping: &mut SuitMapping) -> Self

Creates a suit-isomorphic hand using the provided suit mapping.

Source

pub fn new_iso(cards: &[Card]) -> (Self, SuitMapping)

Creates a suit-isomorphic hand and returns the suit mapping used.

Methods from Deref<Target = [Card; N]>§

1.57.0 · Source

pub fn as_slice(&self) -> &[T]

Returns a slice containing the entire array. Equivalent to &s[..].

1.77.0 · Source

pub fn each_ref(&self) -> [&T; N]

Borrows each element and returns an array of references with the same size as self.

§Example
let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);

This method is particularly useful if combined with other methods, like map. This way, you can avoid moving the original array if its elements are not Copy.

let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);

// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);
Source

pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])

🔬This is a nightly-only experimental API. (split_array)

Divides one array reference into two at an index.

The first will contain all indices from [0, M) (excluding the index M itself) and the second will contain all indices from [M, N) (excluding the index N itself).

§Panics

Panics if M > N.

§Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.split_array_ref::<0>();
   assert_eq!(left, &[]);
   assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<2>();
    assert_eq!(left, &[1, 2]);
    assert_eq!(right, &[3, 4, 5, 6]);
}

{
    let (left, right) = v.split_array_ref::<6>();
    assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
    assert_eq!(right, &[]);
}
Source

pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])

🔬This is a nightly-only experimental API. (split_array)

Divides one array reference into two at an index from the end.

The first will contain all indices from [0, N - M) (excluding the index N - M itself) and the second will contain all indices from [N - M, N) (excluding the index N itself).

§Panics

Panics if M > N.

§Examples
#![feature(split_array)]

let v = [1, 2, 3, 4, 5, 6];

{
   let (left, right) = v.rsplit_array_ref::<0>();
   assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
   assert_eq!(right, &[]);
}

{
    let (left, right) = v.rsplit_array_ref::<2>();
    assert_eq!(left, &[1, 2, 3, 4]);
    assert_eq!(right, &[5, 6]);
}

{
    let (left, right) = v.rsplit_array_ref::<6>();
    assert_eq!(left, &[]);
    assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}

Trait Implementations§

Source§

impl BitOrAssign<HandN<3>> for Card64

Source§

fn bitor_assign(&mut self, rhs: Flop)

Performs the |= operation. Read more
Source§

impl BufferWrite for HandN<2>

Source§

fn write_to<W: Write>(self, w: &mut W) -> Result<()>

Source§

impl BufferWrite for HandN<3>

Source§

fn write_to<W: Write>(self, w: &mut W) -> Result<()>

Source§

impl BufferWrite for HandN<4>

Source§

fn write_to<W: Write>(self, w: &mut W) -> Result<()>

Source§

impl BufferWrite for HandN<5>

Source§

fn write_to<W: Write>(self, w: &mut W) -> Result<()>

Source§

impl<const N: usize> Clone for HandN<N>

Source§

fn clone(&self) -> HandN<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for HandN<N>

Source§

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

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

impl<const N: usize> Deref for HandN<N>

Source§

type Target = [Card; N]

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<const N: usize> Display for HandN<N>

Source§

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

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

impl From<HandN<3>> for Board

Source§

fn from(flop: Flop) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<HandN<N>> for [Card; N]

Source§

fn from(value: HandN<N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> From<HandN<N>> for Card64

Source§

fn from(hand: HandN<N>) -> Self

Converts to this type from the input type.
Source§

impl<const N: usize> Hash for HandN<N>

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<__IdxT, const N: usize> Index<__IdxT> for HandN<N>
where [Card; N]: Index<__IdxT>,

Source§

type Output = <[Card; N] as Index<__IdxT>>::Output

The returned type after indexing.
Source§

fn index(&self, idx: __IdxT) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<const N: usize> Ord for HandN<N>

Source§

fn cmp(&self, other: &HandN<N>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<const N: usize> PartialEq for HandN<N>

Source§

fn eq(&self, other: &HandN<N>) -> 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> PartialOrd for HandN<N>

Source§

fn partial_cmp(&self, other: &HandN<N>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<const N: usize> Copy for HandN<N>

Source§

impl<const N: usize> Eq for HandN<N>

Source§

impl<const N: usize> StructuralPartialEq for HandN<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for HandN<N>

§

impl<const N: usize> RefUnwindSafe for HandN<N>

§

impl<const N: usize> Send for HandN<N>

§

impl<const N: usize> Sync for HandN<N>

§

impl<const N: usize> Unpin for HandN<N>

§

impl<const N: usize> UnwindSafe for HandN<N>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

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

Source§

fn vzip(self) -> V