Tile

Struct Tile 

Source
pub struct Tile(/* private fields */);
Expand description

Represents one tile (牌).

Encoded as a 6-bit integer:

EncodingShorthandCategory (EN)Category (JP)
0 ..= 81m ..= 9mcharacters萬子
9 ..= 171p ..= 9pdots筒子
18 ..= 261s ..= 9sbamboos索子
27 ..= 301z ..= 4zwinds風牌
31, 32, 335z, 6z, 7zdragons三元牌
34, 35, 360m, 0p, 0sreds赤牌

Note that only red 5’s can be represented (not other numbers or honors).

Details of this encoding is significant and implicitly assumed across the crate. It should never be changed.

§Optional serde support

The common string shorthand (e.g. "1m", "0p", "7z") is used as the serialization format. This ensures readability and interoperability.

Implementations§

Source§

impl Tile

Source

pub const MIN_ENCODING: u8 = 0u8

Source

pub const MAX_ENCODING: u8 = 36u8

Source

pub const MIN: Self

Source

pub const MAX: Self

Source

pub const fn from_encoding(encoding: u8) -> Option<Self>

Source

pub const fn from_num_suit(num: u8, suit: u8) -> Option<Self>

Source

pub fn from_wind(wind: Wind) -> Self

Source

pub const fn is_valid(self) -> bool

Source

pub const fn is_normal(self) -> bool

Not red 5

Source

pub const fn is_red(self) -> bool

Red 5 (赤牌)

Source

pub const fn has_red(self) -> bool

Either red or normal 5

Source

pub const fn is_numeral(self) -> bool

Numerals (数牌) := Characters (萬子) + Dots (筒子) + Bamboos (索子)

Source

pub const fn is_pure_terminal(self) -> bool

Pure terminals (老頭牌) := {1,9}{m,p,s}

Source

pub const fn is_middle(self) -> bool

Middle numerals (中張牌) := {2..=8}{m,p,s}

Source

pub const fn is_wind(self) -> bool

Winds (風牌) := {1,2,3,4}z (correspond to {E,S,W,N})

Source

pub const fn is_dragon(self) -> bool

Dragons (三元牌) := {5,6,7}z (correspond to {blue, green, red} dragons).

Source

pub const fn is_honor(self) -> bool

Honors (字牌) := Winds (風牌) + Dragons (三元牌)

Source

pub const fn is_terminal(self) -> bool

Terminals (么九牌) := Pure terminals (老頭牌) + Honors (字牌)

Source

pub const fn encoding(self) -> u8

Source

pub const fn normal_encoding(self) -> u8

Encoding of this tile, except red 5 is converted to normal 5

Source

pub const fn red_encoding(self) -> u8

Encoding of this tile, except normal 5 is converted to red 5

Source

pub const fn to_normal(self) -> Self

Converts a red 5 to normal 5; otherwise no-op.

Source

pub const fn to_red(self) -> Self

Converts normal 5 to red 5; otherwise no-op.

Source

pub const fn wind(self) -> Option<Wind>

Converts to the corresponding wind (ESWN) if this is a wind tile.

Source

pub const fn num(self) -> u8

Returns the “number” part of the shorthand

Source

pub const fn normal_num(self) -> u8

Returns the “number” part of the shorthand, with reds converted to non-red (i.e. 0 => 5).

Source

pub const fn suit(self) -> u8

Returns the “suit” part of the shorthand (0, 1, 2, 3 for m, p, s, z respectively)

Source

pub const fn succ(self) -> Option<Self>

For numerals 1 to 8, returns 2 to 9 respectively. Otherwise None.

Source

pub const fn succ2(self) -> Option<Self>

For numerals 1 to 7, returns 3 to 9 respectively. Otherwise None.

Source

pub const fn pred(self) -> Option<Self>

For numerals 2 to 9, returns 1 to 8 respectively. Otherwise None.

Source

pub const fn pred2(self) -> Option<Self>

For numerals 3 to 9, returns 1 to 7 respectively. Otherwise None.

Source

pub const fn indicated_dora(self) -> Self

Given this tile as the dora-indicator (ドラ表示牌), returns the indicated dora tile (ドラ).

Ref:

Source§

impl Tile

Source

pub fn suit_char(self) -> char

Returns the “suit” part of the shorthand (0, 1, 2, 3 for m, p, s, z respectively)

Source

pub const fn as_str(self) -> &'static str

Returns the standard shorthand string of this tile.

Source

pub const fn unicode(self) -> char

Returns the corresponding codepoint in the Unicode Mahjong Tiles section (1F000 ~ 1F02F)

NOTE: The ordering in Unicode is differerent from Japanese Riichi Mahjong conventions.

Trait Implementations§

Source§

impl Clone for Tile

Source§

fn clone(&self) -> Tile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Tile

Source§

fn default() -> Tile

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Tile

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Tile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromIterator<Tile> for TileMask34

Source§

fn from_iter<T: IntoIterator<Item = Tile>>(tiles: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Tile> for TileSet34

Source§

fn from_iter<T: IntoIterator<Item = Tile>>(tiles: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromIterator<Tile> for TileSet37

Source§

fn from_iter<T: IntoIterator<Item = Tile>>(tiles: T) -> Self

Creates a value from an iterator. Read more
Source§

impl FromStr for Tile

Source§

type Err = UnspecifiedError

The associated error which can be returned from parsing.
Source§

fn from_str(pai_str: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Index<Tile> for TileSet34

Source§

type Output = u8

The returned type after indexing.
Source§

fn index(&self, tile: Tile) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<Tile> for TileSet37

Source§

type Output = u8

The returned type after indexing.
Source§

fn index(&self, tile: Tile) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<Tile> for TileSet34

Source§

fn index_mut(&mut self, tile: Tile) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<Tile> for TileSet37

Source§

fn index_mut(&mut self, tile: Tile) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Into<&str> for Tile

Source§

fn into(self) -> &'static str

Converts this type into the (usually inferred) input type.
Source§

impl Ord for Tile

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Tile

Source§

fn eq(&self, other: &Tile) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Tile

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Tile

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&str> for Tile

Source§

type Error = UnspecifiedError

The type returned in the event of a conversion error.
Source§

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for Tile

Source§

impl Eq for Tile

Source§

impl StructuralPartialEq for Tile

Auto Trait Implementations§

§

impl Freeze for Tile

§

impl RefUnwindSafe for Tile

§

impl Send for Tile

§

impl Sync for Tile

§

impl Unpin for Tile

§

impl UnwindSafe for Tile

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,