sashite-sin 1.0.0

Style Identifier Notation (SIN): a compact, ASCII-only, no_std token encoding a player's side and style in abstract strategy board games.
Documentation
//! A short tour of the SIN API: parse, inspect, transform, build, and validate.
//!
//! Run with `cargo run --example basic`.

use sashite_sin::{Identifier, Letter, ParseError, Side};

fn main() -> Result<(), ParseError> {
    // A SIN token is a single letter: its case encodes the side, the letter is
    // the player-style abbreviation. So "W" is the first-side Western style.
    let western = Identifier::parse("W")?;
    println!("token       : {western}");
    println!("  letter    : {}", western.letter().as_char());
    println!("  side      : {:?}", western.side());
    println!("  to_char   : {}", western.to_char());
    println!("  is_first  : {}", western.is_first());

    // Transformations return new values; the type is `Copy`, so this is cheap.
    let second = western.flipped();
    let chinese = western.with_letter(Letter::try_from_char('C')?);
    println!("flipped     : {second}");
    println!("with_letter : {chinese}");

    // Building from typed components is infallible: every combination is valid.
    let japanese = Identifier::new(Letter::try_from_char('J')?, Side::Second);
    println!("built       : {japanese} (the second-side Japanese style)");

    // Checking validity without constructing an identifier.
    println!("is_valid(\"S\") : {}", Identifier::is_valid("S"));
    println!("is_valid(\"WW\"): {}", Identifier::is_valid("WW"));

    Ok(())
}