Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rust/cardano-blockchain-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ dashmap = "6.1.0"
blake2b_simd = "1.0.2"
minicbor = { version = "0.25.1", features = ["alloc"] }
num-traits = "0.2.19"
ed25519-dalek = "2.1.1"
ed25519-dalek = "2.1.1"
serde = "1.0.210"
31 changes: 30 additions & 1 deletion rust/cardano-blockchain-types/src/slot.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
//! Block Slot

use std::{
cmp::Ordering,
ops::{MulAssign, Sub},
};

use serde::Serialize;

use crate::conversion::from_saturating;

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Default, Serialize)]

/// Slot on the blockchain, typically one slot equals one second. However chain
/// parameters can alter how long a slot is.
pub struct Slot(u64);
Expand Down Expand Up @@ -33,3 +42,23 @@ impl From<Slot> for u64 {
val.0
}
}

impl MulAssign<u64> for Slot {
fn mul_assign(&mut self, rhs: u64) {
self.0 *= rhs;
}
}

impl PartialOrd for Slot {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.0.partial_cmp(&other.0)
}
}

impl Sub for Slot {
type Output = Slot;

fn sub(self, rhs: Slot) -> Self::Output {
Slot(self.0.saturating_sub(rhs.0))
}
}
Loading