pub struct Card(pub Ordinal);
Expand description
wiki | A simple card object wrapping a u8
A simple new-type wrapper around the Ordinal
value,
which is just an alias for u8.
Tuple Fields§
§0: Ordinal
Implementations§
source§impl Card
impl Card
sourcepub const fn from_i32(v: i32) -> Option<Card>
pub const fn from_i32(v: i32) -> Option<Card>
Create a new Card
from an integer value
use onejoker::prelude::*;
let c = Card::from_i32(3).unwrap();
assert_eq!(c, JOKER);
sourcepub const fn from_rank_suit(r: Rank, s: Suit) -> Card
pub const fn from_rank_suit(r: Rank, s: Suit) -> Card
Create a new Card
from a Rank
and a Suit
If the Rank
and Suit
objects are valid, this cannot fail,
so it returns a real Card
, not an Option.
use onejoker::prelude::*;
let c = Card::from_rank_suit(Rank::Ace, Suit::Spade);
assert_eq!(c, ACE_OF_SPADES);
sourcepub const fn low_ace_fix(v: Card) -> Card
pub const fn low_ace_fix(v: Card) -> Card
Ensure correct flavor of ace for low-ace decks
Return a card value unmolested, unless it’s a high ace, in which case return the low ace of the same suit.
use onejoker::prelude::*;
let c = Card::from_i32(63).unwrap();
assert_eq!(c, ACE_OF_SPADES);
assert_eq!(Card::low_ace_fix(c), LOW_ACE_OF_SPADES);
sourcepub const fn high_ace_fix(v: Card) -> Card
pub const fn high_ace_fix(v: Card) -> Card
Ensure correct flavor of ace for high-ace decks
Return a card value unmolested, unless it’s a low ace, in which case return the high ace of the same suit.
use onejoker::prelude::*;
let c = Card::from_i32(4).unwrap();
assert_eq!(c, LOW_ACE_OF_CLUBS);
assert_eq!(Card::high_ace_fix(c), ACE_OF_CLUBS);
sourcepub const fn rank(&self) -> Rank
pub const fn rank(&self) -> Rank
Rank of the card, if any.
Rank is Rank::None
for jokers or illegal values
use onejoker::prelude::*;
assert_eq!(Rank::Deuce, DEUCE_OF_CLUBS.rank());
assert_eq!(Rank::None, BLACK_JOKER.rank());
sourcepub const fn suit(&self) -> Suit
pub const fn suit(&self) -> Suit
Suit of the card if any.
Suit is Suit::None
for jokers or illegal values.
use onejoker::prelude::*;
assert_eq!(Suit::Club, TREY_OF_CLUBS.suit());
assert_eq!(Suit::None, JOKER.suit());
sourcepub const fn is_card(&self) -> bool
pub const fn is_card(&self) -> bool
Does the object represent an actual card, and not an illegal value?
use onejoker::prelude::*;
assert!(ACE_OF_SPADES.is_card());
assert!(JOKER.is_card());
assert!(! Card(0).is_card());
sourcepub const fn is_red(&self) -> bool
pub const fn is_red(&self) -> bool
Is the card a diamond, heart, or red/colored joker?
use onejoker::prelude::*;
assert!(ACE_OF_DIAMONDS.is_red());
assert!(JOKER.is_red()); // Yes, jokers have no suit, but are red/black
assert!(! KING_OF_SPADES.is_red());
sourcepub const fn is_black(&self) -> bool
pub const fn is_black(&self) -> bool
Is the card a club, spade, or black joker?
use onejoker::prelude::*;
assert!(ACE_OF_CLUBS.is_black());
assert!(BLACK_JOKER.is_black());
assert!(! QUEEN_OF_DIAMONDS.is_black());
sourcepub const fn is_joker(&self) -> bool
pub const fn is_joker(&self) -> bool
Is the card any kind of joker?
use onejoker::prelude::*;
assert!(JOKER.is_joker());
assert!(BLACK_JOKER.is_joker());
assert!(WHITE_JOKER.is_joker());
assert!(! ACE_OF_CLUBS.is_joker());
sourcepub const fn is_ace(&self) -> bool
pub const fn is_ace(&self) -> bool
Is the card an ace (high or low)?
use onejoker::prelude::*;
assert!(ACE_OF_CLUBS.is_ace());
assert!(LOW_ACE_OF_DIAMONDS.is_ace());
assert!(! QUEEN_OF_HEARTS.is_ace());
sourcepub const fn is_diamond(&self) -> bool
pub const fn is_diamond(&self) -> bool
Is the card suit $x?
sourcepub fn to_unicode(&self) -> String
pub fn to_unicode(&self) -> String
Produce text output with Unicode suit symbol
use onejoker::prelude::*;
assert_eq!(ACE_OF_SPADES.to_unicode(), "A♠");
assert_eq!(JOKER.to_unicode(), "Jk");
sourcepub fn to_unicode_single(&self) -> String
pub fn to_unicode_single(&self) -> String
Produce the single-character Unicode version of this card
Unicode code points (U+1F0A1..U+1F0DF) represent whole playing cards.
use onejoker::prelude::*;
assert_eq!(ACE_OF_SPADES.to_unicode_single(), "🂡")
sourcepub fn full_name(&self) -> String
pub fn full_name(&self) -> String
Full English name of card, e.g. “ace of spades”
use onejoker::prelude::*;
assert_eq!(JACK_OF_DIAMONDS.full_name(), "jack of diamonds");
assert_eq!(JOKER.full_name(), "joker");
sourcepub const fn from_const_str(st: &str) -> Card
pub const fn from_const_str(st: &str) -> Card
Const function to create a Card
from a string literal
use onejoker::prelude::*;
assert_eq!(ACE_OF_CLUBS, Card::from_const_str("Ac"));
assert_eq!(JOKER, Card::from_const_str("Jk"));
Trait Implementations§
source§impl<'de> Deserialize<'de> for Card
impl<'de> Deserialize<'de> for Card
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl Ord for Card
impl Ord for Card
source§impl PartialEq for Card
impl PartialEq for Card
source§impl PartialOrd for Card
impl PartialOrd for Card
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Card
impl Eq for Card
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> 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: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)