| Crates.io | poker-face |
| lib.rs | poker-face |
| version | 0.2.0 |
| created_at | 2023-09-17 08:39:10.5915+00 |
| updated_at | 2025-12-04 09:29:08.734119+00 |
| description | A hand evaluator for Texas Hold'em poker, using the Rust Match control flow construct. |
| homepage | https://github.com/davassi/poker-face |
| repository | https://github.com/davassi/poker-face |
| max_upload_size | |
| id | 974931 |
| size | 59,536 |
A fast and idiomatic Rust implementation of a Texas Hold'em poker hand evaluator. This library showcases Rust's powerful pattern matching capabilities by evaluating 5-card poker hands using native match control flow with array and struct patterns.
match expressions with array and struct patterns for clean, readable hand evaluationhand!, newcard!, assert_rank!) for working with cards and handsSee the MatchHandEvaluator implementation for details on the pattern-matching approach.
Add poker-face to your Cargo.toml:
[dependencies]
poker-face = "0.2.0"
Or use cargo:
cargo add poker-face
The library provides convenient macros for working with poker hands:
use pokerface::{hand, newcard, assert_rank, Rank, Card, Suit};
fn main() {
// Create and evaluate hands using the hand! macro
let royal = hand!["Ad","Kd","Qd","Jd","10d"];
assert_eq!(Rank::evaluate(&royal), Rank::RoyalFlush);
// Create individual cards
let ace_hearts = newcard!["Ah"];
assert_eq!(ace_hearts, Card::new(14, Suit::Hearts));
// Test hand rankings
assert_rank!(hand!["Kd", "Kh", "Kc", "Ks", "Qd"], Rank::FourOfAKind);
assert_rank!(hand!["2d", "2h", "Qc", "Qs", "Qd"], Rank::FullHouse);
}
The package includes an interactive command-line tool for demonstrations:
# Run directly with cargo
cargo run -q
# Or build and install
cargo build --release
cargo install --path .
pokerface
Example output:
Poker Face - 🦀 for ♠️ ♣️ ♥️ ♦️
1. Let's shuffle a deck...
2. Let's take 2 hands of 5 cards each from the deck
Player 1 has: J♥️ 10♥️ 9♠️ 7♠️ 5♥️
Player 2 has: K♥️ K♣️ K♦️ Q♦️ 6♥️
3. Let's evaluate the hands...
Player 1 has a [HighCard with a highcard of value J♥️]
Player 2 has a [ThreeOfAKind]
4. Celebrate the winner:
The winner is Player 2!
The evaluator recognizes all standard Texas Hold'em poker hands:
Poker-Face uses Rust's pattern matching to evaluate hands in a readable and efficient way. Instead of using lookup tables or bitwise operations, it leverages Rust's structural pattern matching on arrays and structs. This approach makes the code:
Check out the MatchHandEvaluator source to see pattern matching in action.
Full API documentation is available on docs.rs.
Key types and functions:
Card: Represents a playing card with rank and suitRank: Enum representing all poker hand rankingshand!: Macro for creating hands from string notationnewcard!: Macro for creating individual cardsassert_rank!: Test macro for validating hand rankingsContributions are welcome! If you have suggestions for new features or find any issues, please:
All feedback is appreciated!
Licensed under either of:
at your option.
Built with Rust 🦀 for poker enthusiasts ♠️ ♣️ ♥️ ♦️