use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[must_use]
pub struct Lsn(u64);
impl Lsn {
#[inline]
pub const fn new(value: u64) -> Self {
Lsn(value)
}
#[inline]
#[must_use]
pub const fn get(self) -> u64 {
self.0
}
}
impl fmt::Display for Lsn {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<Lsn> for u64 {
#[inline]
fn from(lsn: Lsn) -> Self {
lsn.0
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_lsn_get_roundtrips_value() {
assert_eq!(Lsn::new(0).get(), 0);
assert_eq!(Lsn::new(u64::MAX).get(), u64::MAX);
}
#[test]
fn test_lsn_ordering_is_numeric() {
assert!(Lsn::new(0) < Lsn::new(1));
assert!(Lsn::new(100) > Lsn::new(99));
assert_eq!(Lsn::new(5), Lsn::new(5));
}
#[test]
fn test_lsn_converts_to_u64() {
assert_eq!(u64::from(Lsn::new(123)), 123);
}
#[test]
fn test_lsn_display_is_the_number() {
assert_eq!(Lsn::new(42).to_string(), "42");
}
}