pub struct Identifier { /* private fields */ }Expand description
A parsed PIN token: the identity of a piece at the level of notation.
An Identifier bundles the four attributes a token encodes — a
Letter abbreviation, a Side, a State, and a terminal flag — into
a single 4-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 → state → terminal.
§Examples
use sashite_pin::{Identifier, Side, State};
let rook: Identifier = "+r".parse()?;
assert_eq!(rook.letter().as_char(), 'R');
assert_eq!(rook.side(), Side::Second);
assert_eq!(rook.state(), State::Enhanced);
assert!(!rook.is_terminal());
// Transformations are cheap and infallible; the value is `Copy`.
assert_eq!(rook.flipped().normalized().encode().as_str(), "R");Implementations§
Source§impl Identifier
impl Identifier
Sourcepub const fn new(
letter: Letter,
side: Side,
state: State,
terminal: bool,
) -> Self
pub const fn new( letter: Letter, side: Side, state: State, terminal: bool, ) -> Self
Builds an identifier from its four typed components.
This is infallible: because each component type is valid by construction, every combination denotes a valid PIN token.
§Examples
use sashite_pin::{Identifier, Letter, Side, State};
let p = Identifier::new(
Letter::try_from_char('R').unwrap(),
Side::Second,
State::Enhanced,
false,
);
assert_eq!(p.encode().as_str(), "+r");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 PIN token (empty,
too long, or malformed).
§Examples
use sashite_pin::Identifier;
let king = Identifier::parse("K^")?;
assert!(king.is_first());
assert!(king.is_terminal());Sourcepub const fn is_valid(input: &str) -> bool
pub const fn is_valid(input: &str) -> bool
Reports whether input is a valid PIN token, without allocating or
constructing an identifier on the caller’s side.
Sourcepub fn encode(self) -> EncodedPin
pub fn encode(self) -> EncodedPin
Returns the canonical, allocation-free string encoding of this token.
Sourcepub const fn is_terminal(self) -> bool
pub const fn is_terminal(self) -> bool
Reports whether the piece is terminal (the ^ marker is present).
Sourcepub const fn is_normal(self) -> bool
pub const fn is_normal(self) -> bool
Reports whether the state is State::Normal.
Sourcepub const fn is_enhanced(self) -> bool
pub const fn is_enhanced(self) -> bool
Reports whether the state is State::Enhanced.
Sourcepub const fn is_diminished(self) -> bool
pub const fn is_diminished(self) -> bool
Reports whether the state is State::Diminished.
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.
Sourcepub const fn with_state(self, state: State) -> Self
pub const fn with_state(self, state: State) -> Self
Returns a copy with the state replaced.
Sourcepub const fn with_terminal(self, terminal: bool) -> Self
pub const fn with_terminal(self, terminal: bool) -> Self
Returns a copy with the terminal flag replaced.
Sourcepub const fn enhanced(self) -> Self
pub const fn enhanced(self) -> Self
Returns a copy in the State::Enhanced state.
Sourcepub const fn diminished(self) -> Self
pub const fn diminished(self) -> Self
Returns a copy in the State::Diminished state.
Sourcepub const fn normalized(self) -> Self
pub const fn normalized(self) -> Self
Returns a copy in the baseline State::Normal state.
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 moreSource§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
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 ==.