use std::ops::{Deref, RangeInclusive};
use miden_protocol::block::BlockNumber;
#[derive(Debug, Clone, Copy)]
pub struct ScopedBlockNum(BlockNumber);
impl ScopedBlockNum {
pub(super) fn new(block_num: BlockNumber) -> Self {
Self(block_num)
}
#[cfg(test)]
pub(crate) fn new_unchecked(block_num: BlockNumber) -> Self {
Self(block_num)
}
pub(crate) fn range_from(self, start: BlockNumber) -> ScopedBlockRange {
debug_assert!(start <= self.0, "derived range start {start} exceeds its end {}", self.0);
ScopedBlockRange(start..=self.0)
}
}
impl Deref for ScopedBlockNum {
type Target = BlockNumber;
fn deref(&self) -> &BlockNumber {
&self.0
}
}
#[derive(Debug, Clone)]
pub struct ScopedBlockRange(RangeInclusive<BlockNumber>);
impl ScopedBlockRange {
pub(super) fn new(range: RangeInclusive<BlockNumber>) -> Self {
Self(range)
}
pub(crate) fn start(&self) -> BlockNumber {
*self.0.start()
}
pub(crate) fn end(&self) -> BlockNumber {
*self.0.end()
}
pub(crate) fn scoped_end(&self) -> ScopedBlockNum {
ScopedBlockNum(*self.0.end())
}
pub(crate) fn into_inner(self) -> RangeInclusive<BlockNumber> {
self.0
}
}