pub struct BlockHeight(/* private fields */);Expand description
A block height. Zero denotes the genesis block.
This type is not meant for constructing height based timelocks. It is a general purpose
blockheight abstraction. For locktimes please see [locktime::absolute::Height].
This is a thin wrapper around a u32 that may take on all values of a u32.
Implementations§
Source§impl BlockHeight
impl BlockHeight
Sourcepub const ZERO: BlockHeight
pub const ZERO: BlockHeight
Block height 0, the genesis block.
Sourcepub const MIN: BlockHeight = Self::ZERO
pub const MIN: BlockHeight = Self::ZERO
The minimum block height (0), the genesis block.
Sourcepub const MAX: BlockHeight
pub const MAX: BlockHeight
The maximum block height.
Sourcepub const fn from_u32(inner: u32) -> BlockHeight
pub const fn from_u32(inner: u32) -> BlockHeight
Constructs a new block height from a u32.
Sourcepub fn checked_sub(self, other: BlockHeight) -> Option<BlockHeightInterval>
pub fn checked_sub(self, other: BlockHeight) -> Option<BlockHeightInterval>
Attempt to subtract two BlockHeights, returning None if overflow occurred.
Sourcepub fn checked_add(self, other: BlockHeightInterval) -> Option<BlockHeight>
pub fn checked_add(self, other: BlockHeightInterval) -> Option<BlockHeight>
Attempt to add an interval to this BlockHeight, returning None if overflow occurred.
Sourcepub const fn saturating_add(self, rhs: BlockHeightInterval) -> BlockHeight
pub const fn saturating_add(self, rhs: BlockHeightInterval) -> BlockHeight
Saturating integer addition.
Computes self + rhs, saturating at BlockHeight::MAX instead of overflowing.
Sourcepub const fn saturating_sub(self, rhs: BlockHeightInterval) -> BlockHeight
pub const fn saturating_sub(self, rhs: BlockHeightInterval) -> BlockHeight
Saturating integer subtraction.
Computes self - rhs, saturating at BlockHeight::MIN instead of overflowing.
Trait Implementations§
Source§impl<'a> Add<&'a BlockHeightInterval> for &BlockHeight
impl<'a> Add<&'a BlockHeightInterval> for &BlockHeight
Source§type Output = <BlockHeight as Add<BlockHeightInterval>>::Output
type Output = <BlockHeight as Add<BlockHeightInterval>>::Output
+ operator.Source§fn add(
self,
rhs: &BlockHeightInterval,
) -> <&BlockHeight as Add<&'a BlockHeightInterval>>::Output
fn add( self, rhs: &BlockHeightInterval, ) -> <&BlockHeight as Add<&'a BlockHeightInterval>>::Output
+ operation. Read moreSource§impl Add<&BlockHeightInterval> for BlockHeight
impl Add<&BlockHeightInterval> for BlockHeight
Source§type Output = <BlockHeight as Add<BlockHeightInterval>>::Output
type Output = <BlockHeight as Add<BlockHeightInterval>>::Output
+ operator.Source§fn add(
self,
rhs: &BlockHeightInterval,
) -> <BlockHeight as Add<&BlockHeightInterval>>::Output
fn add( self, rhs: &BlockHeightInterval, ) -> <BlockHeight as Add<&BlockHeightInterval>>::Output
+ operation. Read moreSource§impl Add<BlockHeightInterval> for &BlockHeight
impl Add<BlockHeightInterval> for &BlockHeight
Source§type Output = <BlockHeight as Add<BlockHeightInterval>>::Output
type Output = <BlockHeight as Add<BlockHeightInterval>>::Output
+ operator.Source§fn add(
self,
rhs: BlockHeightInterval,
) -> <&BlockHeight as Add<BlockHeightInterval>>::Output
fn add( self, rhs: BlockHeightInterval, ) -> <&BlockHeight as Add<BlockHeightInterval>>::Output
+ operation. Read moreSource§impl Add<BlockHeightInterval> for BlockHeight
impl Add<BlockHeightInterval> for BlockHeight
Source§type Output = BlockHeight
type Output = BlockHeight
+ operator.Source§fn add(
self,
rhs: BlockHeightInterval,
) -> <BlockHeight as Add<BlockHeightInterval>>::Output
fn add( self, rhs: BlockHeightInterval, ) -> <BlockHeight as Add<BlockHeightInterval>>::Output
+ operation. Read moreSource§impl<'a> Arbitrary<'a> for BlockHeight
Available on crate feature arbitrary only.
impl<'a> Arbitrary<'a> for BlockHeight
arbitrary only.Source§fn arbitrary(u: &mut Unstructured<'a>) -> Result<BlockHeight, Error>
fn arbitrary(u: &mut Unstructured<'a>) -> Result<BlockHeight, Error>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl Binary for BlockHeight
impl Binary for BlockHeight
Source§impl Clone for BlockHeight
impl Clone for BlockHeight
Source§fn clone(&self) -> BlockHeight
fn clone(&self) -> BlockHeight
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BlockHeight
impl Debug for BlockHeight
Source§impl Decodable for BlockHeight
Available on crate feature encoding only.
impl Decodable for BlockHeight
encoding only.Source§type Decoder = BlockHeightDecoder
type Decoder = BlockHeightDecoder
Source§impl<'de> Deserialize<'de> for BlockHeight
Available on crate feature serde only.
impl<'de> Deserialize<'de> for BlockHeight
serde only.Source§fn deserialize<D>(d: D) -> Result<BlockHeight, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(d: D) -> Result<BlockHeight, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl Display for BlockHeight
impl Display for BlockHeight
Source§impl Encodable for BlockHeight
Available on crate feature encoding only.
impl Encodable for BlockHeight
encoding only.Source§type Encoder<'e> = BlockHeightEncoder<'e>
type Encoder<'e> = BlockHeightEncoder<'e>
Source§impl From<BlockHeight> for u32
impl From<BlockHeight> for u32
Source§fn from(height: BlockHeight) -> u32
fn from(height: BlockHeight) -> u32
Source§impl From<Height> for BlockHeight
impl From<Height> for BlockHeight
Source§fn from(h: Height) -> BlockHeight
fn from(h: Height) -> BlockHeight
Converts a [locktime::absolute::Height] to a BlockHeight.
An absolute locktime block height has a maximum value of absolute::LOCK_TIME_THRESHOLD
minus one, while BlockHeight may take the full range of u32.
Source§impl From<u32> for BlockHeight
impl From<u32> for BlockHeight
Source§fn from(inner: u32) -> BlockHeight
fn from(inner: u32) -> BlockHeight
Source§impl FromStr for BlockHeight
impl FromStr for BlockHeight
Source§type Err = ParseIntError
type Err = ParseIntError
Source§fn from_str(s: &str) -> Result<BlockHeight, <BlockHeight as FromStr>::Err>
fn from_str(s: &str) -> Result<BlockHeight, <BlockHeight as FromStr>::Err>
s to return a value of this type. Read moreSource§impl Hash for BlockHeight
impl Hash for BlockHeight
Source§impl LowerHex for BlockHeight
impl LowerHex for BlockHeight
Source§impl Octal for BlockHeight
impl Octal for BlockHeight
Source§impl Ord for BlockHeight
impl Ord for BlockHeight
Source§fn cmp(&self, other: &BlockHeight) -> Ordering
fn cmp(&self, other: &BlockHeight) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for BlockHeight
impl PartialEq for BlockHeight
Source§impl PartialOrd for BlockHeight
impl PartialOrd for BlockHeight
Source§impl Serialize for BlockHeight
Available on crate feature serde only.
impl Serialize for BlockHeight
serde only.Source§fn serialize<S>(
&self,
s: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
s: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<'a> Sub<&'a BlockHeight> for &BlockHeight
impl<'a> Sub<&'a BlockHeight> for &BlockHeight
Source§fn sub(
self,
rhs: &BlockHeight,
) -> <&BlockHeight as Sub<&'a BlockHeight>>::Output
fn sub( self, rhs: &BlockHeight, ) -> <&BlockHeight as Sub<&'a BlockHeight>>::Output
- operation. Read moreSource§impl Sub<&BlockHeight> for BlockHeight
impl Sub<&BlockHeight> for BlockHeight
Source§fn sub(self, rhs: &BlockHeight) -> <BlockHeight as Sub<&BlockHeight>>::Output
fn sub(self, rhs: &BlockHeight) -> <BlockHeight as Sub<&BlockHeight>>::Output
- operation. Read moreSource§impl<'a> Sub<&'a BlockHeightInterval> for &BlockHeight
impl<'a> Sub<&'a BlockHeightInterval> for &BlockHeight
Source§type Output = <BlockHeight as Sub<BlockHeightInterval>>::Output
type Output = <BlockHeight as Sub<BlockHeightInterval>>::Output
- operator.Source§fn sub(
self,
rhs: &BlockHeightInterval,
) -> <&BlockHeight as Sub<&'a BlockHeightInterval>>::Output
fn sub( self, rhs: &BlockHeightInterval, ) -> <&BlockHeight as Sub<&'a BlockHeightInterval>>::Output
- operation. Read moreSource§impl Sub<&BlockHeightInterval> for BlockHeight
impl Sub<&BlockHeightInterval> for BlockHeight
Source§type Output = <BlockHeight as Sub<BlockHeightInterval>>::Output
type Output = <BlockHeight as Sub<BlockHeightInterval>>::Output
- operator.Source§fn sub(
self,
rhs: &BlockHeightInterval,
) -> <BlockHeight as Sub<&BlockHeightInterval>>::Output
fn sub( self, rhs: &BlockHeightInterval, ) -> <BlockHeight as Sub<&BlockHeightInterval>>::Output
- operation. Read moreSource§impl Sub<BlockHeight> for &BlockHeight
impl Sub<BlockHeight> for &BlockHeight
Source§fn sub(self, rhs: BlockHeight) -> <&BlockHeight as Sub<BlockHeight>>::Output
fn sub(self, rhs: BlockHeight) -> <&BlockHeight as Sub<BlockHeight>>::Output
- operation. Read moreSource§impl Sub<BlockHeightInterval> for &BlockHeight
impl Sub<BlockHeightInterval> for &BlockHeight
Source§type Output = <BlockHeight as Sub<BlockHeightInterval>>::Output
type Output = <BlockHeight as Sub<BlockHeightInterval>>::Output
- operator.Source§fn sub(
self,
rhs: BlockHeightInterval,
) -> <&BlockHeight as Sub<BlockHeightInterval>>::Output
fn sub( self, rhs: BlockHeightInterval, ) -> <&BlockHeight as Sub<BlockHeightInterval>>::Output
- operation. Read moreSource§impl Sub<BlockHeightInterval> for BlockHeight
impl Sub<BlockHeightInterval> for BlockHeight
Source§type Output = BlockHeight
type Output = BlockHeight
- operator.Source§fn sub(
self,
rhs: BlockHeightInterval,
) -> <BlockHeight as Sub<BlockHeightInterval>>::Output
fn sub( self, rhs: BlockHeightInterval, ) -> <BlockHeight as Sub<BlockHeightInterval>>::Output
- operation. Read moreSource§impl Sub for BlockHeight
impl Sub for BlockHeight
Source§type Output = BlockHeightInterval
type Output = BlockHeightInterval
- operator.Source§fn sub(self, rhs: BlockHeight) -> <BlockHeight as Sub>::Output
fn sub(self, rhs: BlockHeight) -> <BlockHeight as Sub>::Output
- operation. Read moreSource§impl TryFrom<&str> for BlockHeight
impl TryFrom<&str> for BlockHeight
Source§type Error = ParseIntError
type Error = ParseIntError
Source§fn try_from(
s: &str,
) -> Result<BlockHeight, <BlockHeight as TryFrom<&str>>::Error>
fn try_from( s: &str, ) -> Result<BlockHeight, <BlockHeight as TryFrom<&str>>::Error>
Source§impl TryFrom<BlockHeight> for Height
impl TryFrom<BlockHeight> for Height
Source§fn try_from(
h: BlockHeight,
) -> Result<Height, <Height as TryFrom<BlockHeight>>::Error>
fn try_from( h: BlockHeight, ) -> Result<Height, <Height as TryFrom<BlockHeight>>::Error>
Converts a BlockHeight to a [locktime::absolute::Height].
An absolute locktime block height has a maximum value of absolute::LOCK_TIME_THRESHOLD
minus one, while BlockHeight may take the full range of u32.
Source§type Error = ConversionError
type Error = ConversionError
Source§impl TryFrom<String> for BlockHeight
Available on crate feature alloc only.
impl TryFrom<String> for BlockHeight
alloc only.