use std::fmt;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct ObjectId(u64);
impl ObjectId {
pub const fn new(raw: u64) -> Self {
ObjectId(raw)
}
pub const fn raw(self) -> u64 {
self.0
}
pub const fn is_none(self) -> bool {
self.0 == 0
}
}
impl fmt::Display for ObjectId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "obj#{}", self.0)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_is_none_sentinel() {
assert!(ObjectId::default().is_none());
assert_eq!(ObjectId::default().raw(), 0);
}
#[test]
fn non_zero_is_not_none() {
let id = ObjectId::new(42);
assert!(!id.is_none());
assert_eq!(id.raw(), 42);
}
#[test]
fn display_format() {
assert_eq!(ObjectId::new(7).to_string(), "obj#7");
}
}