pub struct Card(/* private fields */);Expand description
One of the 52 cards, stored as its index rank * 4 + suit.
Every Card value is valid: it can only be built from an index in
0..52, a rank and suit in range, or parsed from text.
use native_solver::Card;
let card: Card = "As".parse()?;
assert_eq!((card.rank(), card.suit()), (12, 3));
assert_eq!(card.to_string(), "As");
assert_eq!(Card::new(12, 3), Some(card));Implementations§
Source§impl Card
impl Card
Sourcepub const fn new(rank: u8, suit: u8) -> Option<Card>
pub const fn new(rank: u8, suit: u8) -> Option<Card>
The card with the given rank and suit, or None if either is out of range.
rank is in 0..13 (0 = “2”, 12 = “A”) and suit in 0..4 (clubs,
diamonds, hearts, spades).
Sourcepub const fn from_index(index: u8) -> Option<Card>
pub const fn from_index(index: u8) -> Option<Card>
The card with index index in 0..52 (rank * 4 + suit), or None
if the index is out of range.
Trait Implementations§
impl Copy for Card
impl Eq for Card
Source§impl Extend<Card> for CardSet
impl Extend<Card> for CardSet
Source§fn extend<I: IntoIterator<Item = Card>>(&mut self, cards: I)
fn extend<I: IntoIterator<Item = Card>>(&mut self, cards: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl FromIterator<Card> for CardSet
impl FromIterator<Card> for CardSet
Source§impl FromStr for Card
impl FromStr for Card
Source§fn from_str(s: &str) -> Result<Card, CardParseError>
fn from_str(s: &str) -> Result<Card, CardParseError>
Parses the two-character notation, e.g. "As", "Td", "2c". Rank
and suit are case-insensitive.
§Errors
Returns a CardParseError naming the part that is wrong: the
length, the rank, or the suit.
Source§type Err = CardParseError
type Err = CardParseError
The associated error which can be returned from parsing.
Source§impl Ord for Card
impl Ord for Card
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for Card
impl PartialOrd for Card
impl StructuralPartialEq for Card
Auto Trait Implementations§
impl Forget for Card
impl Freeze for Card
impl Move for Card
impl RefUnwindSafe for Card
impl Send for Card
impl Sync for Card
impl Unpin for Card
impl UnsafeUnpin for Card
impl UnwindSafe for Card
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
Mutably borrows from an owned value. Read more
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> ⓘ
Converts
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> ⓘ
Converts
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