Crate poker[][src]

Poker

poker is a crate for efficient poker hand evaluation ported into Rust from the treys Python package. This packages introduces the algorithms that are vital for speedy evaluation, which have been added on to or made more idiomatic for Rust where appropriate.

use poker::{cards, Card, EvalClass, Evaluator, Rank};

// Create a reusable evaluator
let eval = Evaluator::new();

// Parse a `Vec` of cards from a str
let cards: Vec<Card> = cards!("Ks Js Ts Qs As").try_collect()?;

// Evaluate the hand
let hand = eval.evaluate(cards)?;

assert!(matches!(
    hand.class(),
    EvalClass::StraightFlush {
        high_rank: Rank::Ace
    }
));
assert!(hand.is_royal_flush());

Modules

card

Create and manage poker cards with suits and ranks.

error

Two different error types that may be encountered when trying to parse Card types from strings, or when trying to evaluate hands.

evaluate

Anything and everything about evaluating poker hands.

Macros

box_cards

Use this macro to chain two or more slices of Card into a single boxed slice of Card. This may be useful for bundling a hand and poker board together for evaluation, as in Texas Holdem.

card

A utility macro for creating a single card.

cards

A utility macro for creating multiple cards.

Structs

Card

A single playing card.

Eval

The result of a successful poker hand evaluation. When printed in Display format, shows the proper, qualified name of the poker hand.

Evaluator

This structure does all the heavy lifting of evaluating poker hands.

Enums

EvalClass

A utility enumeration type for pattern matching against the result of Eval::class. Each variant represents a class of poker hand. Royal flush is not included, but can be matched against EvalClass:StraightFlush { high_card: Rank::Ace } if desired.

EvalError

An error that can be thrown when evaluating poker hands.

ParseCardError

An error than can be thrown when parsing Card types from strings.

Rank

An enumeration type for representing the thirteen card ranks, from two to ace.

Suit

An enumeration type for representing the four card suits.