Skip to content

Commit 3a74de4

Browse files
committed
fix(cardano-blockchain-types): add more trait to slot
Signed-off-by: bkioshn <[email protected]>
1 parent fe48d5a commit 3a74de4

File tree

1 file changed

+25
-1
lines changed
  • rust/cardano-blockchain-types/src

1 file changed

+25
-1
lines changed

rust/cardano-blockchain-types/src/slot.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
//! Block Slot
2+
3+
use std::{cmp::Ordering, ops::{MulAssign, Sub}};
4+
25
use crate::conversion::from_saturating;
36

4-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
7+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Default)]
8+
59
/// Slot on the blockchain, typically one slot equals one second. However chain
610
/// parameters can alter how long a slot is.
711
pub struct Slot(u64);
@@ -33,3 +37,23 @@ impl From<Slot> for u64 {
3337
val.0
3438
}
3539
}
40+
41+
impl MulAssign<u64> for Slot {
42+
fn mul_assign(&mut self, rhs: u64) {
43+
self.0 *= rhs;
44+
}
45+
}
46+
47+
impl PartialOrd for Slot {
48+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
49+
self.0.partial_cmp(&other.0)
50+
}
51+
}
52+
53+
impl Sub for Slot {
54+
type Output = Slot;
55+
56+
fn sub(self, rhs: Slot) -> Self::Output {
57+
Slot(self.0.saturating_sub(rhs.0))
58+
}
59+
}

0 commit comments

Comments
 (0)