spru 0.1.0

Reusable components for the spru strategy and digital board game framework.
Documentation
use std::{cmp, fmt};

/// Uniquely identifies a player within a game. Since each [Client](crate::Client) is aassociated
/// with a single player, it also identifies that client. Note that `player` also includes
/// non-interactive participants, such as spectators.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct Id(pub(crate) u32);

impl Id {
    pub fn into_u32(self) -> u32 {
        self.0
    }

    pub(crate) const ZERO: Self = Self(0);
}

impl cmp::PartialEq<u32> for Id {
    fn eq(&self, other: &u32) -> bool {
        &self.0 == other
    }
}

#[cfg(feature = "test-util")]
#[allow(missing_docs)]
impl Id {
    pub fn test_new(id: u32) -> Self {
        Self(id)
    }
}

impl fmt::Display for Id {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "p{}", self.0)
    }
}