Enum poker::ParseCardError[][src]

pub enum ParseCardError {
    InvalidLength {
        original_input: String,
    },
    InvalidRank {
        original_input: String,
        incorrect_char: char,
    },
    InvalidSuit {
        original_input: String,
        incorrect_char: char,
    },
}

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

Examples

An input with invalid length yields ParseCardError::InvalidLength.

use poker::{Card, ParseCardError};
let ten_of_clubs = "10c"; // not two characters; use 'T' instead of '10'!
let result = ten_of_clubs.parse::<Card>();
assert_eq!(
    result,
    Err(ParseCardError::InvalidLength {
        original_input: "10c".into()
    })
);

If an input is two characters, ParseCardError::InvalidRank will be thrown if the first character, representing the card’s rank, is not one of ‘23456789TJQKA’.

use poker::{Card, ParseCardError};
let jack_of_clubs = "jc";
let result = jack_of_clubs.parse::<Card>();
assert_eq!(
    result,
    Err(ParseCardError::InvalidRank {
        original_input: "jc".into(),
        incorrect_char: 'j'
    })
);

Similarly, a two-character input, with a second character representing the suit, does not contain one of “chsd”, ParseCardError::InvalidSuit will be thrown.

use poker::{Card, ParseCardError};
let two_of_diamonds = "2D";
let result = two_of_diamonds.parse::<Card>();
assert_eq!(
    result,
    Err(ParseCardError::InvalidSuit {
        original_input: "2D".into(),
        incorrect_char: 'D'
    })
);

Variants

InvalidLength

A string to be interpreted as a Card must be exactly two characters long. This variant is used if the input does not have meet this criterion.

Show fields

Fields of InvalidLength

original_input: String

The input that incited this error, converted to a String if needed. The original input is also used for calculating and reporting the incorrect number of characters received.

InvalidRank

A string to be interpreted as a Card must have its first character be one of “23456789TJQKA”, otherwise, this error will be thrown and indicate the incorrect character.

Show fields

Fields of InvalidRank

original_input: String

The input that incited this error, converted to a String if needed.

incorrect_char: char

The actual character within the input that was unexpected and could not be interpreted as a card rank.

InvalidSuit

A string to be interpreted as a Card must have its first character be one of “23456789TJQKA”, otherwise, this error will be thrown and indicate the incorrect character.

Show fields

Fields of InvalidSuit

original_input: String

The input that incited this error, converted to a String if needed.

incorrect_char: char

The actual character within the input that was unexpected and could not be interpreted as a card suit.

Trait Implementations

impl Clone for ParseCardError[src]

impl Debug for ParseCardError[src]

impl Display for ParseCardError[src]

impl Eq for ParseCardError[src]

impl Error for ParseCardError[src]

impl PartialEq<ParseCardError> for ParseCardError[src]

impl StructuralEq for ParseCardError[src]

impl StructuralPartialEq for ParseCardError[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,