Standardize error headings

Created headings for a couple of function error descriptions to be
consistent with the rest of the crate.

Added a description explaining why Mega is not allowed in a
denomination.
This commit is contained in:
Jamil Lambert, PhD 2024-07-03 17:46:40 +01:00
parent 75f317a689
commit 47e367f011
1 changed files with 25 additions and 7 deletions

View File

@ -18,6 +18,19 @@ use internals::write_err;
/// A set of denominations in which amounts can be expressed. /// A set of denominations in which amounts can be expressed.
/// ///
/// # Accepted Denominations
///
/// All upper or lower case, excluding SI prefix (c, m, u) which must be lower case.
/// - Singular: BTC, cBTC, mBTC, uBTC
/// - Plural or singular: sat, satoshi, bit
///
/// # Note
///
/// Due to ambiguity between mega and milli we prohibit usage of leading capital 'M'. It is
/// more important to protect users from incorrectly using a capital M to mean milli than to
/// allow Megabitcoin which is not a realistic denomination, and Megasatoshi which is
/// equivalent to cBTC which is allowed.
///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
@ -107,13 +120,12 @@ impl FromStr for Denomination {
/// Converts from a `str` to a `Denomination`. /// Converts from a `str` to a `Denomination`.
/// ///
/// # Accepted Denominations /// # Errors
/// ///
/// All upper or lower case, excluding SI prefix (c, m, u) which must be lower case. /// - If the denomination begins with a capital `M` a `PossiblyConfusingDenominationError` is
/// - Singular: BTC, cBTC, mBTC, uBTC /// returned.
/// - Plural or singular: sat, satoshi, bit
/// ///
/// Due to ambiguity between mega and milli we prohibit usage of leading capital 'M'. /// - 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::*;
@ -946,7 +958,10 @@ impl Amount {
/// Converts this [`Amount`] in floating-point notation with a given /// Converts this [`Amount`] in floating-point notation with a given
/// denomination. /// denomination.
/// Can return error if the amount is too big, too precise or negative. ///
/// # Errors
///
/// If the amount is too big, too precise or negative.
/// ///
/// Please be aware of the risk of using floating-point numbers. /// Please be aware of the risk of using floating-point numbers.
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
@ -1302,7 +1317,10 @@ impl SignedAmount {
/// Convert this [`SignedAmount`] in floating-point notation with a given /// Convert this [`SignedAmount`] in floating-point notation with a given
/// denomination. /// denomination.
/// Can return error if the amount is too big, too precise or negative. ///
/// # Errors
///
/// If the amount is too big, too precise or negative.
/// ///
/// Please be aware of the risk of using floating-point numbers. /// Please be aware of the risk of using floating-point numbers.
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]