Struct cardpack::cards::card::Card

source ·
pub struct Card {
    pub weight: u32,
    pub index: String,
    pub suit: Suit,
    pub rank: Rank,
}
Expand description

Card is the core struct in the library. A Card is made up of a Rank, a Suit, weight, which is an integer that controls how a card is sorted in a Pile or as a part of a Vector, and index, which is a short String representation of the card, suitable for serialization in text format.

Fields§

§weight: u32

Used by the Pile struct to sort Cards.

§index: String

The identity indicator in the corner of a playing card, such as AS for ace of spades.

§suit: Suit§rank: Rank

Implementations§

source§

impl Card

source

pub fn new(rank: Rank, suit: Suit) -> Self

Instantiates a Card with the weight determined by the passed in Rank and Suit.

source

pub fn from_index_strings(rank: &'static str, suit: &'static str) -> Self

Instantiates a new Card with the default weight as defined in the fluent templates.

source

pub fn to_rank_weight(&self) -> Self

Returns a Card where the sorting emphasizes its Rank weight over its Suit weight. So K♥ A♥ A♠ K♠ would return A♠ A♥ K♠ K♥ instead of A♠ K♠ A♥ K♥.

source

pub fn shift_rank_weight_left(&self, i: usize) -> Self

Returns a version of the Card, with a geometric Rank weighted operation has been performed on it.

source

pub fn symbol(&self, lid: &LanguageIdentifier) -> String

Returns a Symbol String for the Card.

source

pub fn symbol_colorized(&self, lid: &LanguageIdentifier) -> String

Returns a Symbol String for the Card in the traditional colors for the Suits.

source

pub fn blank_card() -> Self

👎Deprecated since 0.4.15: Use Card::default()
source

pub fn count(&self) -> u32

A unique index of a Card relative to other cards in a Pile prioritized by Rank and then by Suit, such that a 2 of spades is lower than a 3 of clubs. While Card.weight prioritizes by Suit and then by Rank.

source

pub fn is_valid(&self) -> bool

A valid Card is one where the Rank and Suit are not blank. Cards are blank when an invalid Rank or Suit are passed in.

Trait Implementations§

source§

impl Clone for Card

source§

fn clone(&self) -> Card

Returns a copy 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 Debug for Card

source§

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

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

impl Default for Card

Defaults to a blank Card.

source§

fn default() -> Card

Returns the “default value” for a type. Read more
source§

impl Display for Card

source§

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

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

impl FromIterator<Card> for Pile

source§

fn from_iter<T: IntoIterator<Item = Card>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<Card> for Standard52Set

source§

fn from_iter<T: IntoIterator<Item = Card>>(iter: T) -> Self

Creates a value from an iterator. Read more
source§

impl Hash for Card

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 Named for Card

source§

fn name(&self) -> &str

source§

fn index(&self, lid: &LanguageIdentifier) -> String

Returns the value of the names’ index in the fluent templates. Read more
source§

fn long(&self, lid: &LanguageIdentifier) -> String

Returns the value of the names’ long value in the fluent templates. Read more
source§

fn default_weight(&self) -> u32

Returns the default weight for a name. Weight is used to sort cards.
source§

fn fluent_value(&self, key_section: &str, lid: &LanguageIdentifier) -> String

This is the core method for getting fluent values. the index, long, and default weight methods are all just methods simplifying the call to this method.
source§

fn index_default(&self) -> String

Returns the default, US_ENGLISH value of the names’ index value in the fluent templates. Read more
source§

fn long_default(&self) -> String

Returns the default, US_ENGLISH value of the names’ long value in the fluent templates.
source§

fn default_prime(&self) -> u32

source§

impl Ord for Card

source§

fn cmp(&self, other: &Card) -> 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 + PartialOrd,

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

impl PartialEq for Card

source§

fn eq(&self, other: &Card) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Card

source§

fn partial_cmp(&self, other: &Card) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for Card

source§

impl StructuralPartialEq for Card

Auto Trait Implementations§

§

impl Freeze for Card

§

impl RefUnwindSafe for Card

§

impl Send for Card

§

impl Sync for Card

§

impl Unpin for Card

§

impl UnwindSafe for Card

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> AnyEq for T
where T: Any + PartialEq,

source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

source§

fn as_any(&self) -> &(dyn Any + 'static)

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

§

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§

default 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>,

§

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>,

§

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