use core::any::TypeId;
#[derive(Debug)]
pub enum Mutable {}
impl MutabilityMarker for Mutable {}
#[derive(Debug)]
pub enum Immutable {}
impl MutabilityMarker for Immutable {}
pub trait MutabilityMarker: Send + Sync + 'static + private::Sealed {}
mod private {
pub trait Sealed {}
impl Sealed for super::Mutable {}
impl Sealed for super::Immutable {}
}
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Mutability {
Mutable,
Immutable,
}
impl Mutability {
pub fn of<M: MutabilityMarker>() -> Self {
if TypeId::of::<M>() == TypeId::of::<Mutable>() {
Mutability::Mutable
} else if TypeId::of::<M>() == TypeId::of::<Immutable>() {
Mutability::Immutable
} else {
unreachable!("mutability marker trait should be sealed")
}
}
pub const fn is_mutable(self) -> bool {
matches!(self, Self::Mutable)
}
pub const fn is_immutable(self) -> bool {
matches!(self, Self::Immutable)
}
}