Struct deckofcards::Card
source · Expand description
A Card
has a Rank
and a Suit
and represents a card from the normal 52-card
playing deck.
Example
use deckofcards::{Card, Rank, Suit};
let card = Card::new(Rank::Jack, Suit::Hearts);
Fields
rank: Rank
The card’s Rank
, e.g. Jack
suit: Suit
The card’s Suit
, e.g. Hearts
Implementations
sourceimpl Card
impl Card
sourcepub fn cmp_rank_then_suit(&self, other: &Card) -> Ordering
pub fn cmp_rank_then_suit(&self, other: &Card) -> Ordering
Compares by rank and then suit
sourcepub fn cmp_desc_rank_then_suit(&self, other: &Card) -> Ordering
pub fn cmp_desc_rank_then_suit(&self, other: &Card) -> Ordering
Compares by descending rank and then suit
sourcepub fn cmp_suit_then_rank(&self, other: &Card) -> Ordering
pub fn cmp_suit_then_rank(&self, other: &Card) -> Ordering
Compares by suit and then rank
sourcepub fn cmp_suit_then_desc_rank(&self, other: &Card) -> Ordering
pub fn cmp_suit_then_desc_rank(&self, other: &Card) -> Ordering
Compares by suit and then rank
sourcepub fn from_str(s: &str) -> Result<Card, &'static str>
pub fn from_str(s: &str) -> Result<Card, &'static str>
Creates a card from a string such, e.g. “AS” returns Ace of Spades
sourcepub fn to_str(&self) -> String
pub fn to_str(&self) -> String
Turns the card into a short string consisting of rank, suit, e.g. “AS”
sourcepub fn name(&self) -> String
pub fn name(&self) -> String
Returns an English formatted name of the card, e.g. “Ace of Spades”
sourcepub fn ordinal(&self) -> usize
pub fn ordinal(&self) -> usize
Returns an ordinal for the card which is a unique number which can be used for indexing
sourcepub fn is_diamonds(&self) -> bool
pub fn is_diamonds(&self) -> bool
Tests if the card is Diamonds
sourcepub fn all_cards() -> &'static [Card]
pub fn all_cards() -> &'static [Card]
Returns an array slice containing all the cards in a standard 52-card deck
pub fn iterator() -> Iter<'static, Card>
Trait Implementations
sourceimpl AddAssign<Card> for Hand
impl AddAssign<Card> for Hand
sourcefn add_assign(&mut self, rhs: Card)
fn add_assign(&mut self, rhs: Card)
Performs the
+=
operation. Read moresourceimpl Ord for Card
impl Ord for Card
1.21.0 · sourcefn 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 · sourcefn 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
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialOrd<Card> for Card
impl PartialOrd<Card> for Card
sourcefn partial_cmp(&self, other: &Card) -> Option<Ordering>
fn partial_cmp(&self, other: &Card) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Card
impl Eq for Card
impl StructuralEq for Card
impl StructuralPartialEq for Card
Auto Trait Implementations
impl RefUnwindSafe for Card
impl Send for Card
impl Sync for Card
impl Unpin for Card
impl UnwindSafe for Card
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more