pub struct Dice { /* private fields */ }Expand description
A roll of exactly five six-sided dice, stored as face counts.
Order never matters in Yahtzee, so the multiset is the canonical
representation: counts[f - 1] dice show face f. The five-dice
invariant is enforced by every constructor, which is why scoring
functions never have to handle short or long rolls.
Implementations§
Source§impl Dice
impl Dice
Sourcepub const fn from_faces(faces: [u8; 5]) -> Option<Self>
pub const fn from_faces(faces: [u8; 5]) -> Option<Self>
Builds a roll from five faces in any order.
Returns None if any face is outside 1..=6.
Sourcepub const fn from_counts(counts: [u8; 6]) -> Option<Self>
pub const fn from_counts(counts: [u8; 6]) -> Option<Self>
Builds a roll from face counts (counts[f - 1] dice show f).
Returns None unless the counts sum to exactly five.
Sourcepub const fn yahtzee_face(self) -> Option<u8>
pub const fn yahtzee_face(self) -> Option<u8>
The face of a five-of-a-kind, or None if this roll is not one.
Sourcepub fn keeps(self) -> impl Iterator<Item = Keep>
pub fn keeps(self) -> impl Iterator<Item = Keep>
All distinct sub-multisets of this roll, from Keep::EMPTY to
keeping everything. A roll has at most 32 keeps (all faces
distinct) and as few as 6 (five of a kind).
Trait Implementations§
impl Copy for Dice
impl Eq for Dice
Source§impl FromStr for Dice
impl FromStr for Dice
Source§fn from_str(s: &str) -> Result<Self, ParseDiceError>
fn from_str(s: &str) -> Result<Self, ParseDiceError>
Parses five digits 1–6, ignoring whitespace: "13446".
Source§type Err = ParseDiceError
type Err = ParseDiceError
impl StructuralPartialEq for Dice
Auto Trait Implementations§
impl Freeze for Dice
impl RefUnwindSafe for Dice
impl Send for Dice
impl Sync for Dice
impl Unpin for Dice
impl UnsafeUnpin for Dice
impl UnwindSafe for Dice
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more