Add missing links

The use of links in the rustdocs was inconsistent.

Links have been added when missing.

[`locktime::absolute::Height`] and [`locktime::relative::Height`] did
not work and `(crate::locktime)` was appended to fix it.
This commit is contained in:
Jamil Lambert, PhD 2024-07-03 17:58:57 +01:00
parent 47e367f011
commit 6dd5af9678
6 changed files with 48 additions and 48 deletions

View File

@ -122,10 +122,10 @@ impl FromStr for Denomination {
/// ///
/// # Errors /// # Errors
/// ///
/// - If the denomination begins with a capital `M` a `PossiblyConfusingDenominationError` is /// - If the denomination begins with a capital `M` a [`PossiblyConfusingDenominationError`] is
/// returned. /// 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<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
use self::ParseDenominationError::*; use self::ParseDenominationError::*;
@ -525,7 +525,7 @@ fn is_too_precise(s: &str, precision: usize) -> Option<usize> {
const INPUT_STRING_LEN_LIMIT: usize = 50; const INPUT_STRING_LEN_LIMIT: usize = 50;
/// Parses a decimal string in the given denomination into a satoshi value and a /// 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( fn parse_signed_to_satoshi(
mut s: &str, mut s: &str,
denom: Denomination, denom: Denomination,
@ -1017,7 +1017,7 @@ impl Amount {
self.display_in(denom).show_denomination().to_string() 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. /// Checked addition.
/// ///
@ -1173,13 +1173,13 @@ impl core::iter::Sum for Amount {
/// A helper/builder that displays amount with specified settings. /// 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 /// * Ability to select denomination
/// * Show or hide denomination /// * Show or hide denomination
/// * Dynamically-selected denomination - show in sats if less than 1 BTC. /// * 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 /// padding, alignment... The formatting works like floats from `core` but note that precision will
/// **never** be lossy - that means no rounding. /// **never** be lossy - that means no rounding.
/// ///
@ -1376,12 +1376,12 @@ impl SignedAmount {
self.display_in(denom).show_denomination().to_string() 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`]. /// Get the absolute value of this [`SignedAmount`].
pub fn abs(self) -> SignedAmount { SignedAmount(self.0.abs()) } 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()) } pub fn unsigned_abs(self) -> Amount { Amount(self.0.unsigned_abs()) }
/// Returns a number representing sign of this [`SignedAmount`]. /// 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. /// Calculates the sum over the iterator using checked arithmetic.
pub trait CheckedSum<R>: private::SumSeal<R> { pub trait CheckedSum<R>: private::SumSeal<R> {
/// Calculates the sum over the iterator using checked arithmetic. If an over or underflow would /// 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<R>; fn checked_sum(self) -> Option<R>;
} }

View File

@ -65,10 +65,10 @@ impl From<BlockHeight> for u32 {
} }
impl From<absolute::Height> for BlockHeight { impl From<absolute::Height> 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` /// 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 /// (500,000,000) where as a [`BlockHeight`] is a thin wrapper around a `u32`, the two types are
/// not interchangeable. /// not interchangeable.
fn from(h: absolute::Height) -> Self { Self::from_u32(h.to_consensus_u32()) } fn from(h: absolute::Height) -> Self { Self::from_u32(h.to_consensus_u32()) }
} }
@ -76,10 +76,10 @@ impl From<absolute::Height> for BlockHeight {
impl TryFrom<BlockHeight> for absolute::Height { impl TryFrom<BlockHeight> for absolute::Height {
type Error = absolute::ConversionError; 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` /// 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 /// (500,000,000) where as a [`BlockHeight`] is a thin wrapper around a `u32`, the two types are
/// not interchangeable. /// not interchangeable.
fn try_from(h: BlockHeight) -> Result<Self, Self::Error> { fn try_from(h: BlockHeight) -> Result<Self, Self::Error> {
absolute::Height::from_consensus(h.to_u32()) absolute::Height::from_consensus(h.to_u32())
@ -132,20 +132,20 @@ impl From<BlockInterval> for u32 {
} }
impl From<relative::Height> for BlockInterval { impl From<relative::Height> 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 /// 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()) } fn from(h: relative::Height) -> Self { Self::from_u32(h.value().into()) }
} }
impl TryFrom<BlockInterval> for relative::Height { impl TryFrom<BlockInterval> for relative::Height {
type Error = TooBigForRelativeBlockHeightError; 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 /// 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<Self, Self::Error> { fn try_from(h: BlockInterval) -> Result<Self, Self::Error> {
let h = h.to_u32(); let h = h.to_u32();
if h > u16::MAX as u32 { if h > u16::MAX as u32 {

View File

@ -42,14 +42,14 @@ impl FeeRate {
/// Fee rate used to compute dust amount. /// Fee rate used to compute dust amount.
pub const DUST: FeeRate = FeeRate::from_sat_per_vb_unchecked(3); 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) } 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 /// # Errors
/// ///
/// Returns `None` on arithmetic overflow. /// Returns [`None`] on arithmetic overflow.
pub fn from_sat_per_vb(sat_vb: u64) -> Option<Self> { pub fn from_sat_per_vb(sat_vb: u64) -> Option<Self> {
// 1 vb == 4 wu // 1 vb == 4 wu
// 1 sat/vb == 1/4 sat/wu // 1 sat/vb == 1/4 sat/wu
@ -57,7 +57,7 @@ impl FeeRate {
Some(FeeRate(sat_vb.checked_mul(1000 / 4)?)) 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)) } pub const fn from_sat_per_vb_unchecked(sat_vb: u64) -> Self { FeeRate(sat_vb * (1000 / 4)) }
/// Returns raw fee rate. /// Returns raw fee rate.
@ -73,34 +73,34 @@ impl FeeRate {
/// Checked multiplication. /// 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> { self.0.checked_mul(rhs).map(Self) } pub fn checked_mul(self, rhs: u64) -> Option<Self> { self.0.checked_mul(rhs).map(Self) }
/// Checked division. /// 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> { self.0.checked_div(rhs).map(Self) } pub fn checked_div(self, rhs: u64) -> Option<Self> { self.0.checked_div(rhs).map(Self) }
/// Checked weight multiplication. /// Checked weight multiplication.
/// ///
/// Computes the absolute fee amount for a given [`Weight`] at this fee rate. /// 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<Amount> { pub fn checked_mul_by_weight(self, rhs: Weight) -> Option<Amount> {
let sats = self.0.checked_mul(rhs.to_wu())?.checked_add(999)? / 1000; let sats = self.0.checked_mul(rhs.to_wu())?.checked_add(999)? / 1000;
Some(Amount::from_sat(sats)) 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. /// if an overflow occurred.
/// ///
/// This is equivalent to `Self::checked_mul_by_weight()`. /// This is equivalent to `Self::checked_mul_by_weight()`.
pub fn fee_wu(self, weight: Weight) -> Option<Amount> { self.checked_mul_by_weight(weight) } pub fn fee_wu(self, weight: Weight) -> Option<Amount> { 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. /// 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)`. /// `Self::fee_wu(weight)`.
pub fn fee_vb(self, vb: u64) -> Option<Amount> { pub fn fee_vb(self, vb: u64) -> Option<Amount> {
Weight::from_vb(vb).and_then(|w| self.fee_wu(w)) Weight::from_vb(vb).and_then(|w| self.fee_wu(w))

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0 // 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; use core::fmt;
@ -39,7 +39,7 @@ impl Height {
/// The maximum absolute block height. /// The maximum absolute block height.
pub const MAX: Self = Height(LOCK_TIME_THRESHOLD - 1); 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`. /// The input string may or may not contain a typical hex prefix e.g., `0x`.
pub fn from_hex(s: &str) -> Result<Self, ParseHeightError> { pub fn from_hex(s: &str) -> Result<Self, ParseHeightError> {
@ -70,7 +70,7 @@ impl Height {
} }
} }
/// Converts this `Height` to its inner `u32` value. /// Converts this [`Height`] to its inner `u32` value.
#[inline] #[inline]
pub fn to_consensus_u32(self) -> u32 { self.0 } 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). /// The maximum absolute block time (Sun Feb 07 2106 06:28:15 GMT+0000).
pub const MAX: Self = Time(u32::MAX); 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`. /// The input string may or may not contain a typical hex prefix e.g., `0x`.
pub fn from_hex(s: &str) -> Result<Self, ParseTimeError> { parse_hex(s, Self::from_consensus) } pub fn from_hex(s: &str) -> Result<Self, ParseTimeError> { 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] #[inline]
pub fn to_consensus_u32(self) -> u32 { self.0 } pub fn to_consensus_u32(self) -> u32 { self.0 }
} }

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: CC0-1.0 // 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; use core::fmt;

View File

@ -13,7 +13,7 @@ pub const WITNESS_SCALE_FACTOR: usize = 4;
/// Represents block weight - the weight of a transaction or block. /// 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. /// up the types as well as basic formatting features.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@ -43,21 +43,21 @@ impl Weight {
/// The minimum transaction weight for a valid serialized transaction. /// The minimum transaction weight for a valid serialized transaction.
pub const MIN_TRANSACTION: Weight = Weight(Self::WITNESS_SCALE_FACTOR * 60); 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) } 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) } 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<Self> { wu.checked_mul(1000).map(Weight) } pub fn from_kwu(wu: u64) -> Option<Self> { 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<Self> { pub fn from_vb(vb: u64) -> Option<Self> {
vb.checked_mul(Self::WITNESS_SCALE_FACTOR).map(Weight::from_wu) 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 /// # 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) } 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) } 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 { pub const fn from_non_witness_data_size(non_witness_size: u64) -> Self {
Weight(non_witness_size * Self::WITNESS_SCALE_FACTOR) Weight(non_witness_size * Self::WITNESS_SCALE_FACTOR)
} }
@ -105,22 +105,22 @@ impl Weight {
/// Checked addition. /// 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> { self.0.checked_add(rhs.0).map(Self) } pub fn checked_add(self, rhs: Self) -> Option<Self> { self.0.checked_add(rhs.0).map(Self) }
/// Checked subtraction. /// 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> { self.0.checked_sub(rhs.0).map(Self) } pub fn checked_sub(self, rhs: Self) -> Option<Self> { self.0.checked_sub(rhs.0).map(Self) }
/// Checked multiplication. /// 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> { self.0.checked_mul(rhs).map(Self) } pub fn checked_mul(self, rhs: u64) -> Option<Self> { self.0.checked_mul(rhs).map(Self) }
/// Checked division. /// 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> { self.0.checked_div(rhs).map(Self) } pub fn checked_div(self, rhs: u64) -> Option<Self> { self.0.checked_div(rhs).map(Self) }
} }