agglayer_types/certificate/
height.rs1#[derive(
2 Clone,
3 Copy,
4 Debug,
5 Default,
6 Eq,
7 Ord,
8 PartialEq,
9 PartialOrd,
10 derive_more::Display,
11 derive_more::From,
12 serde::Deserialize,
13 serde::Serialize,
14)]
15#[cfg_attr(feature = "testutils", derive(arbitrary::Arbitrary))]
16#[serde(transparent)]
17pub struct Height(u64);
18
19impl Height {
20 pub const ZERO: Height = Height::new(0);
21
22 pub const fn as_u64(&self) -> u64 {
23 self.0
24 }
25
26 pub const fn new(height: u64) -> Height {
27 Height(height)
28 }
29
30 #[must_use = "The value of the next height is returned but not used"]
31 pub const fn next(&self) -> Height {
32 Height(self.0.checked_add(1).expect("Height overflow"))
33 }
34
35 pub const fn increment(&mut self) {
36 *self = self.next();
37 }
38
39 pub const fn distance_since(&self, o: &Height) -> u64 {
40 self.0
41 .checked_sub(o.0)
42 .expect("Subtracting to negative values")
43 }
44}