// Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. use std::{ fmt::{self, Display, Formatter}, ops::{Add, Sub}, }; #[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Default)] pub struct PushId(u64); impl PushId { #[must_use] pub const fn new(id: u64) -> Self { Self(id) } pub const fn next(&mut self) { self.0 += 1; } } impl From for PushId { fn from(id: u64) -> Self { Self(id) } } impl From for u64 { fn from(id: PushId) -> Self { id.0 } } impl Display for PushId { fn fmt(&self, f: &mut Formatter) -> fmt::Result { write!(f, "{}", self.0) } } impl Sub for PushId { type Output = Self; fn sub(self, rhs: Self) -> Self { Self(self.0 - rhs.0) } } impl Add for PushId { type Output = Self; fn add(self, rhs: u64) -> Self { Self(self.0 + rhs) } } #[test] fn push_id_display() { assert_eq!(PushId::new(42).to_string(), "42"); }