zero-trust-rps 0.0.5

Online Multiplayer Rock Paper Scissors
Documentation
use std::{fmt::Debug, ops::Deref};

/// A container for values that can only be deref'd immutably.
#[repr(transparent)]
#[derive(Clone, Copy)]
pub struct Immutable<T> {
    value: T,
}

impl<T> Immutable<T> {
    #[inline]
    pub fn new(value: T) -> Self {
        Immutable { value }
    }
}

impl<T> Deref for Immutable<T> {
    type Target = T;

    fn deref(&self) -> &Self::Target {
        &self.value
    }
}

impl<T: Debug> Debug for Immutable<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.value.fmt(f)
    }
}

impl<T: Default> Default for Immutable<T> {
    fn default() -> Self {
        Immutable::new(Default::default())
    }
}
impl<T> From<T> for Immutable<T> {
    fn from(value: T) -> Self {
        Immutable::new(value)
    }
}