pub struct Letter(/* private fields */);Expand description
The single-letter abbreviation of a player style.
A Letter is the identity part of a SIN token, independent of side. Per
the specification the abbreviation is case-insensitive (C and c denote
the same style), so a Letter is always stored uppercase; the case of the
original token is carried separately by Side.
§Invariant
The wrapped byte is always an uppercase ASCII letter (b'A'..=b'Z'). Every
constructor enforces this, so the invariant cannot be violated from outside
the crate.
Ordering is alphabetical (A < B < … < Z).
Implementations§
Source§impl Letter
impl Letter
Sourcepub const fn from_ascii(byte: u8) -> Option<(Self, Side)>
pub const fn from_ascii(byte: u8) -> Option<(Self, Side)>
Decodes a raw ASCII byte into a Letter and the Side its case
implies.
Returns None for any byte that is not an ASCII letter. This is the
lossless decoder used by the token parser.
§Examples
use sashite_sin::{Letter, Side};
let (letter, side) = Letter::from_ascii(b'c').unwrap();
assert_eq!(letter.as_char(), 'C');
assert_eq!(side, Side::Second);
assert!(Letter::from_ascii(b'1').is_none());Sourcepub const fn try_from_char(c: char) -> Result<Self, ParseError>
pub const fn try_from_char(c: char) -> Result<Self, ParseError>
Builds a Letter from a char, folding case.
Both 'C' and 'c' yield the same Letter; the case (which encodes
side) is not retained.
§Errors
Returns ParseError::InvalidLetter if c is not an ASCII letter.
§Examples
use sashite_sin::Letter;
assert_eq!(Letter::try_from_char('j').unwrap().as_char(), 'J');
assert!(Letter::try_from_char('+').is_err());