Use impl_op_for_references for block height/interval
We have a new macro for implementing ops with a bunch of reference combos. Lets use it for block `Height` and `Interval`. This patch is strictly additive.
This commit is contained in:
parent
f5e17914b6
commit
9d55922952
|
@ -171,53 +171,55 @@ impl fmt::Display for TooBigForRelativeBlockHeightError {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::error::Error for TooBigForRelativeBlockHeightError {}
|
impl std::error::Error for TooBigForRelativeBlockHeightError {}
|
||||||
|
|
||||||
// height - height = interval
|
crate::internal_macros::impl_op_for_references! {
|
||||||
impl ops::Sub<BlockHeight> for BlockHeight {
|
// height - height = interval
|
||||||
type Output = BlockInterval;
|
impl ops::Sub<BlockHeight> for BlockHeight {
|
||||||
|
type Output = BlockInterval;
|
||||||
|
|
||||||
fn sub(self, rhs: BlockHeight) -> Self::Output {
|
fn sub(self, rhs: BlockHeight) -> Self::Output {
|
||||||
let interval = self.to_u32() - rhs.to_u32();
|
let interval = self.to_u32() - rhs.to_u32();
|
||||||
BlockInterval::from_u32(interval)
|
BlockInterval::from_u32(interval)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// height + interval = height
|
// height + interval = height
|
||||||
impl ops::Add<BlockInterval> for BlockHeight {
|
impl ops::Add<BlockInterval> for BlockHeight {
|
||||||
type Output = BlockHeight;
|
type Output = BlockHeight;
|
||||||
|
|
||||||
fn add(self, rhs: BlockInterval) -> Self::Output {
|
fn add(self, rhs: BlockInterval) -> Self::Output {
|
||||||
let height = self.to_u32() + rhs.to_u32();
|
let height = self.to_u32() + rhs.to_u32();
|
||||||
BlockHeight::from_u32(height)
|
BlockHeight::from_u32(height)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// height - interval = height
|
// height - interval = height
|
||||||
impl ops::Sub<BlockInterval> for BlockHeight {
|
impl ops::Sub<BlockInterval> for BlockHeight {
|
||||||
type Output = BlockHeight;
|
type Output = BlockHeight;
|
||||||
|
|
||||||
fn sub(self, rhs: BlockInterval) -> Self::Output {
|
fn sub(self, rhs: BlockInterval) -> Self::Output {
|
||||||
let height = self.to_u32() - rhs.to_u32();
|
let height = self.to_u32() - rhs.to_u32();
|
||||||
BlockHeight::from_u32(height)
|
BlockHeight::from_u32(height)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// interval + interval = interval
|
// interval + interval = interval
|
||||||
impl ops::Add<BlockInterval> for BlockInterval {
|
impl ops::Add<BlockInterval> for BlockInterval {
|
||||||
type Output = BlockInterval;
|
type Output = BlockInterval;
|
||||||
|
|
||||||
fn add(self, rhs: BlockInterval) -> Self::Output {
|
fn add(self, rhs: BlockInterval) -> Self::Output {
|
||||||
let height = self.to_u32() + rhs.to_u32();
|
let height = self.to_u32() + rhs.to_u32();
|
||||||
BlockInterval::from_u32(height)
|
BlockInterval::from_u32(height)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// interval - interval = interval
|
// interval - interval = interval
|
||||||
impl ops::Sub<BlockInterval> for BlockInterval {
|
impl ops::Sub<BlockInterval> for BlockInterval {
|
||||||
type Output = BlockInterval;
|
type Output = BlockInterval;
|
||||||
|
|
||||||
fn sub(self, rhs: BlockInterval) -> Self::Output {
|
fn sub(self, rhs: BlockInterval) -> Self::Output {
|
||||||
let height = self.to_u32() - rhs.to_u32();
|
let height = self.to_u32() - rhs.to_u32();
|
||||||
BlockInterval::from_u32(height)
|
BlockInterval::from_u32(height)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue