pub struct Identifier { /* private fields */ }Expand description
A parsed SIN token: a player’s identity at the level of notation.
An Identifier bundles the two attributes a token encodes — a Letter
abbreviation and a Side — into a single 2-byte Copy value.
Construction from typed components via Identifier::new is total: every
combination is a valid token, so it cannot fail.
The derived total ordering compares attributes in the order letter → side.
§Examples
use sashite_sin::{Identifier, Side};
let chinese: Identifier = "c".parse()?;
assert_eq!(chinese.letter().as_char(), 'C');
assert_eq!(chinese.side(), Side::Second);
assert_eq!(chinese.to_char(), 'c');
// Transformations are cheap and infallible; the value is `Copy`.
assert_eq!(chinese.flipped().to_char(), 'C');Implementations§
Source§impl Identifier
impl Identifier
Sourcepub const fn new(letter: Letter, side: Side) -> Self
pub const fn new(letter: Letter, side: Side) -> Self
Builds an identifier from its two typed components.
This is infallible: because each component type is valid by construction, every combination denotes a valid SIN token.
§Examples
use sashite_sin::{Identifier, Letter, Side};
let p = Identifier::new(Letter::try_from_char('C').unwrap(), Side::Second);
assert_eq!(p.encode().as_str(), "c");Sourcepub const fn parse(input: &str) -> Result<Self, ParseError>
pub const fn parse(input: &str) -> Result<Self, ParseError>
Parses a string slice into an identifier.
§Errors
Returns a ParseError if input is not a valid SIN token (empty,
too long, or not a single ASCII letter).
§Examples
use sashite_sin::Identifier;
let western = Identifier::parse("W")?;
assert!(western.is_first());
assert_eq!(western.letter().as_char(), 'W');Sourcepub const fn is_valid(input: &str) -> bool
pub const fn is_valid(input: &str) -> bool
Reports whether input is a valid SIN token, without allocating or
constructing an identifier on the caller’s side.
Sourcepub fn encode(self) -> EncodedSin
pub fn encode(self) -> EncodedSin
Returns the canonical, allocation-free string encoding of this token.
Sourcepub const fn to_char(self) -> char
pub const fn to_char(self) -> char
Returns the token as its single cased character: uppercase for
Side::First, lowercase for Side::Second.
§Examples
use sashite_sin::Identifier;
assert_eq!(Identifier::parse("J")?.to_char(), 'J');
assert_eq!(Identifier::parse("j")?.to_char(), 'j');Sourcepub const fn is_first(self) -> bool
pub const fn is_first(self) -> bool
Reports whether the side is Side::First.
Sourcepub const fn is_second(self) -> bool
pub const fn is_second(self) -> bool
Reports whether the side is Side::Second.
Sourcepub const fn with_letter(self, letter: Letter) -> Self
pub const fn with_letter(self, letter: Letter) -> Self
Returns a copy with the abbreviation replaced.
Trait Implementations§
Source§impl Clone for Identifier
impl Clone for Identifier
Source§fn clone(&self) -> Identifier
fn clone(&self) -> Identifier
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Identifier
Source§impl Debug for Identifier
impl Debug for Identifier
Source§impl<'de> Deserialize<'de> for Identifier
impl<'de> Deserialize<'de> for Identifier
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for Identifier
impl Display for Identifier
impl Eq for Identifier
Source§impl FromStr for Identifier
impl FromStr for Identifier
Source§impl Hash for Identifier
impl Hash for Identifier
Source§impl Ord for Identifier
impl Ord for Identifier
Source§fn cmp(&self, other: &Identifier) -> Ordering
fn cmp(&self, other: &Identifier) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for Identifier
impl PartialEq for Identifier
Source§fn eq(&self, other: &Identifier) -> bool
fn eq(&self, other: &Identifier) -> bool
self and other values to be equal, and is used by ==.