pub const NONE_U32: u32 = u32::MAX;
macro_rules! id_type {
($(#[$doc:meta])* $name:ident) => {
$(#[$doc])*
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct $name(pub u32);
impl $name {
pub const NONE: Self = Self(NONE_U32);
pub fn is_none(self) -> bool {
self.0 == NONE_U32
}
pub fn some(self) -> Option<Self> {
if self.is_none() { None } else { Some(self) }
}
pub fn from_opt(opt: Option<Self>) -> Self {
opt.unwrap_or(Self::NONE)
}
}
};
}
id_type! {
FactId
}
id_type! {
EntityId
}