tp_consensus_slots/
lib.rs1#![cfg_attr(not(feature = "std"), no_std)]
21
22use codec::{Decode, Encode};
23
24#[derive(Debug, Encode, Decode, Eq, Clone, Copy, Default, Ord)]
26pub struct Slot(u64);
27
28impl core::ops::Deref for Slot {
29 type Target = u64;
30
31 fn deref(&self) -> &u64 {
32 &self.0
33 }
34}
35
36impl core::ops::Add for Slot {
37 type Output = Self;
38
39 fn add(self, other: Self) -> Self {
40 Self(self.0 + other.0)
41 }
42}
43
44impl core::ops::Add<u64> for Slot {
45 type Output = Self;
46
47 fn add(self, other: u64) -> Self {
48 Self(self.0 + other)
49 }
50}
51
52impl<T: Into<u64> + Copy> core::cmp::PartialEq<T> for Slot {
53 fn eq(&self, eq: &T) -> bool {
54 self.0 == (*eq).into()
55 }
56}
57
58impl<T: Into<u64> + Copy> core::cmp::PartialOrd<T> for Slot {
59 fn partial_cmp(&self, other: &T) -> Option<core::cmp::Ordering> {
60 self.0.partial_cmp(&(*other).into())
61 }
62}
63
64impl Slot {
65 pub fn saturating_add<T: Into<u64>>(self, rhs: T) -> Self {
67 Self(self.0.saturating_add(rhs.into()))
68 }
69
70 pub fn saturating_sub<T: Into<u64>>(self, rhs: T) -> Self {
72 Self(self.0.saturating_sub(rhs.into()))
73 }
74}
75
76#[cfg(feature = "std")]
77impl std::fmt::Display for Slot {
78 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
79 write!(f, "{}", self.0)
80 }
81}
82
83impl From<u64> for Slot {
84 fn from(slot: u64) -> Slot {
85 Slot(slot)
86 }
87}
88
89impl From<Slot> for u64 {
90 fn from(slot: Slot) -> u64 {
91 slot.0
92 }
93}
94
95#[derive(Clone, Debug, Decode, Encode, PartialEq)]
100pub struct EquivocationProof<Header, Id> {
101 pub offender: Id,
103 pub slot: Slot,
105 pub first_header: Header,
107 pub second_header: Header,
109}