diff --git a/units/src/amount.rs b/units/src/amount.rs index 09bb866f3..d32cce72d 100644 --- a/units/src/amount.rs +++ b/units/src/amount.rs @@ -122,10 +122,10 @@ impl FromStr for Denomination { /// /// # Errors /// - /// - If the denomination begins with a capital `M` a `PossiblyConfusingDenominationError` is + /// - If the denomination begins with a capital `M` a [`PossiblyConfusingDenominationError`] is /// returned. /// - /// - If an unknown denomination is used, an `UnknownDenominationError` is returned. + /// - If an unknown denomination is used, an [`UnknownDenominationError`] is returned. fn from_str(s: &str) -> Result { use self::ParseDenominationError::*; @@ -525,7 +525,7 @@ fn is_too_precise(s: &str, precision: usize) -> Option { const INPUT_STRING_LEN_LIMIT: usize = 50; /// Parses a decimal string in the given denomination into a satoshi value and a -/// `bool` indicator for a negative amount. +/// [`bool`] indicator for a negative amount. fn parse_signed_to_satoshi( mut s: &str, denom: Denomination, @@ -1017,7 +1017,7 @@ impl Amount { self.display_in(denom).show_denomination().to_string() } - // Some arithmetic that doesn't fit in `core::ops` traits. + // Some arithmetic that doesn't fit in [`core::ops`] traits. /// Checked addition. /// @@ -1173,13 +1173,13 @@ impl core::iter::Sum for Amount { /// A helper/builder that displays amount with specified settings. /// -/// This provides richer interface than `fmt::Formatter`: +/// This provides richer interface than [`fmt::Formatter`]: /// /// * Ability to select denomination /// * Show or hide denomination /// * Dynamically-selected denomination - show in sats if less than 1 BTC. /// -/// However this can still be combined with `fmt::Formatter` options to precisely control zeros, +/// However this can still be combined with [`fmt::Formatter`] options to precisely control zeros, /// padding, alignment... The formatting works like floats from `core` but note that precision will /// **never** be lossy - that means no rounding. /// @@ -1376,12 +1376,12 @@ impl SignedAmount { self.display_in(denom).show_denomination().to_string() } - // Some arithmetic that doesn't fit in `core::ops` traits. + // Some arithmetic that doesn't fit in [`core::ops`] traits. /// Get the absolute value of this [`SignedAmount`]. pub fn abs(self) -> SignedAmount { SignedAmount(self.0.abs()) } - /// Get the absolute value of this [`SignedAmount`] returning `Amount`. + /// Get the absolute value of this [`SignedAmount`] returning [`Amount`]. pub fn unsigned_abs(self) -> Amount { Amount(self.0.unsigned_abs()) } /// Returns a number representing sign of this [`SignedAmount`]. @@ -1593,7 +1593,7 @@ impl core::iter::Sum for SignedAmount { /// Calculates the sum over the iterator using checked arithmetic. pub trait CheckedSum: private::SumSeal { /// Calculates the sum over the iterator using checked arithmetic. If an over or underflow would - /// happen it returns `None`. + /// happen it returns [`None`]. fn checked_sum(self) -> Option; } diff --git a/units/src/block.rs b/units/src/block.rs index b79023135..659458010 100644 --- a/units/src/block.rs +++ b/units/src/block.rs @@ -65,10 +65,10 @@ impl From for u32 { } impl From for BlockHeight { - /// Converts [`locktime::absolute::Height`] to a [`BlockHeight`]. + /// Converts a [`locktime::absolute::Height`] to a [`BlockHeight`]. /// - /// An absolute locktime block height has a maximum value of `absolute::LOCK_TIME_THRESHOLD` - /// (500,000,000) where as a `BlockHeight` is a thin wrapper around a `u32`, the two types are + /// An absolute locktime block height has a maximum value of [`absolute::LOCK_TIME_THRESHOLD`] + /// (500,000,000) where as a [`BlockHeight`] is a thin wrapper around a `u32`, the two types are /// not interchangeable. fn from(h: absolute::Height) -> Self { Self::from_u32(h.to_consensus_u32()) } } @@ -76,10 +76,10 @@ impl From for BlockHeight { impl TryFrom for absolute::Height { type Error = absolute::ConversionError; - /// Converts [`BlockHeight`] to a [`locktime::absolute::Height`]. + /// Converts a [`BlockHeight`] to a [`locktime::absolute::Height`]. /// - /// An absolute locktime block height has a maximum value of `absolute::LOCK_TIME_THRESHOLD` - /// (500,000,000) where as a `BlockHeight` is a thin wrapper around a `u32`, the two types are + /// An absolute locktime block height has a maximum value of [`absolute::LOCK_TIME_THRESHOLD`] + /// (500,000,000) where as a [`BlockHeight`] is a thin wrapper around a `u32`, the two types are /// not interchangeable. fn try_from(h: BlockHeight) -> Result { absolute::Height::from_consensus(h.to_u32()) @@ -132,20 +132,20 @@ impl From for u32 { } impl From for BlockInterval { - /// Converts [`locktime::relative::Height`] to a [`BlockInterval`]. + /// Converts a [`locktime::relative::Height`] to a [`BlockInterval`]. /// /// A relative locktime block height has a maximum value of `u16::MAX` where as a - /// `BlockInterval` is a thin wrapper around a `u32`, the two types are not interchangeable. + /// [`BlockInterval`] is a thin wrapper around a `u32`, the two types are not interchangeable. fn from(h: relative::Height) -> Self { Self::from_u32(h.value().into()) } } impl TryFrom for relative::Height { type Error = TooBigForRelativeBlockHeightError; - /// Converts [`BlockInterval`] to a [`locktime::relative::Height`]. + /// Converts a [`BlockInterval`] to a [`locktime::relative::Height`]. /// /// A relative locktime block height has a maximum value of `u16::MAX` where as a - /// `BlockInterval` is a thin wrapper around a `u32`, the two types are not interchangeable. + /// [`BlockInterval`] is a thin wrapper around a `u32`, the two types are not interchangeable. fn try_from(h: BlockInterval) -> Result { let h = h.to_u32(); if h > u16::MAX as u32 { diff --git a/units/src/fee_rate.rs b/units/src/fee_rate.rs index 648f34707..901f9ce65 100644 --- a/units/src/fee_rate.rs +++ b/units/src/fee_rate.rs @@ -42,14 +42,14 @@ impl FeeRate { /// Fee rate used to compute dust amount. pub const DUST: FeeRate = FeeRate::from_sat_per_vb_unchecked(3); - /// Constructs `FeeRate` from satoshis per 1000 weight units. + /// Constructs [`FeeRate`] from satoshis per 1000 weight units. pub const fn from_sat_per_kwu(sat_kwu: u64) -> Self { FeeRate(sat_kwu) } - /// Constructs `FeeRate` from satoshis per virtual bytes. + /// Constructs [`FeeRate`] from satoshis per virtual bytes. /// /// # Errors /// - /// Returns `None` on arithmetic overflow. + /// Returns [`None`] on arithmetic overflow. pub fn from_sat_per_vb(sat_vb: u64) -> Option { // 1 vb == 4 wu // 1 sat/vb == 1/4 sat/wu @@ -57,7 +57,7 @@ impl FeeRate { Some(FeeRate(sat_vb.checked_mul(1000 / 4)?)) } - /// Constructs `FeeRate` from satoshis per virtual bytes without overflow check. + /// Constructs [`FeeRate`] from satoshis per virtual bytes without overflow check. pub const fn from_sat_per_vb_unchecked(sat_vb: u64) -> Self { FeeRate(sat_vb * (1000 / 4)) } /// Returns raw fee rate. @@ -73,34 +73,34 @@ impl FeeRate { /// Checked multiplication. /// - /// Computes `self * rhs` returning `None` if overflow occurred. + /// Computes `self * rhs` returning [`None`] if overflow occurred. pub fn checked_mul(self, rhs: u64) -> Option { self.0.checked_mul(rhs).map(Self) } /// Checked division. /// - /// Computes `self / rhs` returning `None` if `rhs == 0`. + /// Computes `self / rhs` returning [`None`] if `rhs == 0`. pub fn checked_div(self, rhs: u64) -> Option { self.0.checked_div(rhs).map(Self) } /// Checked weight multiplication. /// /// Computes the absolute fee amount for a given [`Weight`] at this fee rate. /// - /// `None` is returned if an overflow occurred. + /// [`None`] is returned if an overflow occurred. pub fn checked_mul_by_weight(self, rhs: Weight) -> Option { let sats = self.0.checked_mul(rhs.to_wu())?.checked_add(999)? / 1000; Some(Amount::from_sat(sats)) } - /// Calculates the fee by multiplying this fee rate by weight, in weight units, returning `None` + /// Calculates the fee by multiplying this fee rate by weight, in weight units, returning [`None`] /// if an overflow occurred. /// /// This is equivalent to `Self::checked_mul_by_weight()`. pub fn fee_wu(self, weight: Weight) -> Option { self.checked_mul_by_weight(weight) } - /// Calculates the fee by multiplying this fee rate by weight, in virtual bytes, returning `None` + /// Calculates the fee by multiplying this fee rate by weight, in virtual bytes, returning [`None`] /// if an overflow occurred. /// - /// This is equivalent to converting `vb` to `weight` using `Weight::from_vb` and then calling + /// This is equivalent to converting `vb` to [`Weight`] using [`Weight::from_vb`] and then calling /// `Self::fee_wu(weight)`. pub fn fee_vb(self, vb: u64) -> Option { Weight::from_vb(vb).and_then(|w| self.fee_wu(w)) diff --git a/units/src/locktime/absolute.rs b/units/src/locktime/absolute.rs index 8eb2f95f5..ae8d468a4 100644 --- a/units/src/locktime/absolute.rs +++ b/units/src/locktime/absolute.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: CC0-1.0 -//! Provides `Height` and `Time` types used by the `rust-bitcoin` `absolute::LockTime` type. +//! Provides [`Height`] and [`Time`] types used by the `rust-bitcoin` `absolute::LockTime` type. use core::fmt; @@ -39,7 +39,7 @@ impl Height { /// The maximum absolute block height. pub const MAX: Self = Height(LOCK_TIME_THRESHOLD - 1); - /// Creates a `Height` from a hex string. + /// Creates a [`Height`] from a hex string. /// /// The input string may or may not contain a typical hex prefix e.g., `0x`. pub fn from_hex(s: &str) -> Result { @@ -70,7 +70,7 @@ impl Height { } } - /// Converts this `Height` to its inner `u32` value. + /// Converts this [`Height`] to its inner `u32` value. #[inline] pub fn to_consensus_u32(self) -> u32 { self.0 } } @@ -137,7 +137,7 @@ impl Time { /// The maximum absolute block time (Sun Feb 07 2106 06:28:15 GMT+0000). pub const MAX: Self = Time(u32::MAX); - /// Creates a `Time` from a hex string. + /// Creates a [`Time`] from a hex string. /// /// The input string may or may not contain a typical hex prefix e.g., `0x`. pub fn from_hex(s: &str) -> Result { parse_hex(s, Self::from_consensus) } @@ -166,7 +166,7 @@ impl Time { } } - /// Converts this `Time` to its inner `u32` value. + /// Converts this [`Time`] to its inner `u32` value. #[inline] pub fn to_consensus_u32(self) -> u32 { self.0 } } diff --git a/units/src/locktime/relative.rs b/units/src/locktime/relative.rs index fae92901e..b8c9a8d32 100644 --- a/units/src/locktime/relative.rs +++ b/units/src/locktime/relative.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: CC0-1.0 -//! Provides `Height` and `Time` types used by the `rust-bitcoin` `relative::LockTime` type. +//! Provides [`Height`] and [`Time`] types used by the `rust-bitcoin` `relative::LockTime` type. use core::fmt; diff --git a/units/src/weight.rs b/units/src/weight.rs index 1740c36c2..956c1129c 100644 --- a/units/src/weight.rs +++ b/units/src/weight.rs @@ -13,7 +13,7 @@ pub const WITNESS_SCALE_FACTOR: usize = 4; /// Represents block weight - the weight of a transaction or block. /// -/// This is an integer newtype representing weigth in `wu`. It provides protection against mixing +/// This is an integer newtype representing [`Weight`] in `wu`. It provides protection against mixing /// up the types as well as basic formatting features. #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] @@ -43,21 +43,21 @@ impl Weight { /// The minimum transaction weight for a valid serialized transaction. pub const MIN_TRANSACTION: Weight = Weight(Self::WITNESS_SCALE_FACTOR * 60); - /// Directly constructs `Weight` from weight units. + /// Directly constructs [`Weight`] from weight units. pub const fn from_wu(wu: u64) -> Self { Weight(wu) } - /// Directly constructs `Weight` from usize weight units. + /// Directly constructs [`Weight`] from usize weight units. pub const fn from_wu_usize(wu: usize) -> Self { Weight(wu as u64) } - /// Constructs `Weight` from kilo weight units returning `None` if an overflow occurred. + /// Constructs [`Weight`] from kilo weight units returning [`None`] if an overflow occurred. pub fn from_kwu(wu: u64) -> Option { wu.checked_mul(1000).map(Weight) } - /// Constructs `Weight` from virtual bytes, returning `None` if an overflow occurred. + /// Constructs [`Weight`] from virtual bytes, returning [`None`] if an overflow occurred. pub fn from_vb(vb: u64) -> Option { vb.checked_mul(Self::WITNESS_SCALE_FACTOR).map(Weight::from_wu) } - /// Constructs `Weight` from virtual bytes panicking if an overflow occurred. + /// Constructs [`Weight`] from virtual bytes panicking if an overflow occurred. /// /// # Panics /// @@ -76,13 +76,13 @@ impl Weight { } } - /// Constructs `Weight` from virtual bytes without an overflow check. + /// Constructs [`Weight`] from virtual bytes without an overflow check. pub const fn from_vb_unchecked(vb: u64) -> Self { Weight::from_wu(vb * 4) } - /// Constructs `Weight` from witness size. + /// Constructs [`Weight`] from witness size. pub const fn from_witness_data_size(witness_size: u64) -> Self { Weight(witness_size) } - /// Constructs `Weight` from non-witness size. + /// Constructs [`Weight`] from non-witness size. pub const fn from_non_witness_data_size(non_witness_size: u64) -> Self { Weight(non_witness_size * Self::WITNESS_SCALE_FACTOR) } @@ -105,22 +105,22 @@ impl Weight { /// Checked addition. /// - /// Computes `self + rhs` returning `None` if an overflow occurred. + /// Computes `self + rhs` returning [`None`] if an overflow occurred. pub fn checked_add(self, rhs: Self) -> Option { self.0.checked_add(rhs.0).map(Self) } /// Checked subtraction. /// - /// Computes `self - rhs` returning `None` if an overflow occurred. + /// Computes `self - rhs` returning [`None`] if an overflow occurred. pub fn checked_sub(self, rhs: Self) -> Option { self.0.checked_sub(rhs.0).map(Self) } /// Checked multiplication. /// - /// Computes `self * rhs` returning `None` if an overflow occurred. + /// Computes `self * rhs` returning [`None`] if an overflow occurred. pub fn checked_mul(self, rhs: u64) -> Option { self.0.checked_mul(rhs).map(Self) } /// Checked division. /// - /// Computes `self / rhs` returning `None` if `rhs == 0`. + /// Computes `self / rhs` returning [`None`] if `rhs == 0`. pub fn checked_div(self, rhs: u64) -> Option { self.0.checked_div(rhs).map(Self) } }