Skip to main content

Crate playin_cards

Crate playin_cards 

Source
Expand description

§PLAYIN-CARDS

Crates.io Version docs.rs licence

A crate for representing, formatting, and parsing French-Suited playing cards. The main objective of the project is to provide utility to crates implementing card games or card-game analysis.

§Design

In keeping with the goals of being a lightweight library, as well as best practices with regard to separation of concerns, this crate is designed to be minimal in scope, limiting itself only the representation, parsing, and formatting of playing cards. As such, it does not not provide shuffling or the concept of hands; it attempts to remain independent of any specific card game or rules and focuses only on properties that are truly intrinsic to the cards themselves. That said, design decisions are made, where possible, to provide a featureful and ergonomic base to easily build most common card games, while still remaining generic enough to implement any card game played with a standard deck. This design philosophy maximizes the breadth of use-cases while minimizing dependencies.

Implementing concepts like hands and shuffling remains the responsibility of consumer applications. They can easily do these things in obvious ways, for example, by collecting Card values into a collection such as array or Vec to represent a hand, or making use of the popular external crate rand to provide random shuffling.

§Features

  • Jokers
  • Iterable ranks and suits
  • ASCII and Unicode representations of cards, ranks, and suits
  • Copy semantics for all types
  • Single character representations of cards: 🃞
  • Convert single char to rank or suit
  • Convert 2-character str to card
  • Generate a shoe of arbitrary number of decks, with or without Jokers

§Usage

The main interface is the Card which represents a single playing card which may be one of the cards in a standard 52-card deck of playing cards, or a Joker which may be either black or red. A Card instance can be easily be parsed from a 2-char str with one of A23456789TJQK as the first char and one of SsCcDdHh♥♣♠♦ as the second char.

Card can also be formatted as a 2-char Unicode string such A♣, 5♥, J♠ with the Display trait or as a single-char Unicode card char such as 🃑, 🂵, 🂫 with the UpperHex trait.

Structs§

RankIter
An iterator over the variants of Rank
SuitIter
An iterator over the variants of Suit

Enums§

Card
A French-suited playing card
Color
Color of a Suit or Card. Either Red or Black
ParseError
Error Type for parsing failures
Rank
Ranks of a standard French-suited playing card
Suit
Suits of a standard French-suited playing card

Constants§

CARDS_PER_DECK
number of cards in a standard 52-card deck of French-suited playing cards

Functions§

gen_shoe
Generate an (unshuffled) shoe