[][src]Struct deckofcards::Card

pub struct Card {
    pub rank: Rank,
    pub suit: Suit,
}

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

Methods

impl Card[src]

pub fn new(rank: Rank, suit: Suit) -> Card[src]

Creates a card with the given suit and rank

pub fn cmp_rank_then_suit(&self, other: &Card) -> Ordering[src]

Compares by rank and then suit

pub fn cmp_desc_rank_then_suit(&self, other: &Card) -> Ordering[src]

Compares by descending rank and then suit

pub fn cmp_suit_then_rank(&self, other: &Card) -> Ordering[src]

Compares by suit and then rank

pub fn cmp_suit_then_desc_rank(&self, other: &Card) -> Ordering[src]

Compares by suit and then rank

pub fn from_str(s: &str) -> Result<Card, &'static str>[src]

Creates a card from a string such, e.g. "AS" returns Ace of Spades

pub fn to_str(&self) -> String[src]

Turns the card into a short string consisting of rank, suit, e.g. "AS"

pub fn name(&self) -> String[src]

Returns an English formatted name of the card, e.g. "Ace of Spades"

pub fn ordinal(&self) -> usize[src]

Returns an ordinal for the card which is a unique number which can be used for indexing

pub fn is_hearts(&self) -> bool[src]

Tests if the card is Hearts

pub fn is_clubs(&self) -> bool[src]

Tests if the card is Clubs

pub fn is_spades(&self) -> bool[src]

Tests if the card is Spades

pub fn is_diamonds(&self) -> bool[src]

Tests if the card is Diamonds

pub fn all_cards() -> &'static [Card][src]

Returns an array slice containing all the cards in a standard 52-card deck

pub fn iterator() -> Iter<'static, Card>[src]

Trait Implementations

impl AddAssign<Card> for Hand[src]

impl Clone for Card[src]

impl Copy for Card[src]

impl Debug for Card[src]

impl Display for Card[src]

impl Eq for Card[src]

impl Hash for Card[src]

impl Ord for Card[src]

fn cmp(&self, other: &Card) -> Ordering[src]

Sorts by rank and then suit

impl PartialEq<Card> for Card[src]

impl PartialOrd<Card> for Card[src]

impl StructuralEq for Card[src]

impl StructuralPartialEq for Card[src]

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

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[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>,