Skip to main content

sashite_sin/
side.rs

1//! Player side: the camp a player belongs to.
2
3/// The camp a player belongs to.
4///
5/// In SIN, the *case* of the abbreviation letter encodes the side: an uppercase
6/// letter (`A`–`Z`) denotes [`Side::First`], a lowercase letter (`a`–`z`)
7/// denotes [`Side::Second`]. This mirrors the two-side model of the
8/// [glossary](https://sashite.dev/glossary/): a side is a pure label
9/// (`first` / `second`) that acquires meaning only once a rule system assigns
10/// it to a player or piece.
11///
12/// Unlike a piece side, a *player* side is fixed for the duration of a match,
13/// which is what makes a SIN token a stable player identifier.
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
15#[repr(u8)]
16pub enum Side {
17    /// The `first` side, encoded by an uppercase letter (`A`–`Z`).
18    First = 0,
19    /// The `second` side, encoded by a lowercase letter (`a`–`z`).
20    Second = 1,
21}
22
23impl Side {
24    /// Returns the opposite side.
25    ///
26    /// # Examples
27    ///
28    /// ```
29    /// use sashite_sin::Side;
30    ///
31    /// assert_eq!(Side::First.flip(), Side::Second);
32    /// assert_eq!(Side::Second.flip(), Side::First);
33    /// ```
34    #[must_use]
35    pub const fn flip(self) -> Self {
36        match self {
37            Self::First => Self::Second,
38            Self::Second => Self::First,
39        }
40    }
41}