Change T::from_str(s) to s.parse::<T>() in docs
`s.parse` is more idiomatic and produces more helpful error messages. This has been changed repo wide in docs.
This commit is contained in:
parent
e048b7b003
commit
c835bb9eab
|
@ -421,11 +421,10 @@ impl DerivationPath {
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use bitcoin::bip32::{DerivationPath, ChildNumber};
|
/// use bitcoin::bip32::{DerivationPath, ChildNumber};
|
||||||
/// use std::str::FromStr;
|
|
||||||
///
|
///
|
||||||
/// let base = DerivationPath::from_str("m/42").unwrap();
|
/// let base = "m/42".parse::<DerivationPath>().unwrap();
|
||||||
///
|
///
|
||||||
/// let deriv_1 = base.extend(DerivationPath::from_str("0/1").unwrap());
|
/// let deriv_1 = base.extend("0/1".parse::<DerivationPath>().unwrap());
|
||||||
/// let deriv_2 = base.extend(&[
|
/// let deriv_2 = base.extend(&[
|
||||||
/// ChildNumber::ZERO_NORMAL,
|
/// ChildNumber::ZERO_NORMAL,
|
||||||
/// ChildNumber::ONE_NORMAL
|
/// ChildNumber::ONE_NORMAL
|
||||||
|
@ -447,7 +446,7 @@ impl DerivationPath {
|
||||||
/// use bitcoin::bip32::DerivationPath;
|
/// use bitcoin::bip32::DerivationPath;
|
||||||
/// use std::str::FromStr;
|
/// use std::str::FromStr;
|
||||||
///
|
///
|
||||||
/// let path = DerivationPath::from_str("m/84'/0'/0'/0/1").unwrap();
|
/// let path = "m/84'/0'/0'/0/1".parse::<DerivationPath>().unwrap();
|
||||||
/// const HARDENED: u32 = 0x80000000;
|
/// const HARDENED: u32 = 0x80000000;
|
||||||
/// assert_eq!(path.to_u32_vec(), vec![84 + HARDENED, HARDENED, HARDENED, 0, 1]);
|
/// assert_eq!(path.to_u32_vec(), vec![84 + HARDENED, HARDENED, HARDENED, 0, 1]);
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -134,10 +134,9 @@ impl PublicKey {
|
||||||
/// # Example: Using with `sort_unstable_by_key`
|
/// # Example: Using with `sort_unstable_by_key`
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use std::str::FromStr;
|
|
||||||
/// use bitcoin::PublicKey;
|
/// use bitcoin::PublicKey;
|
||||||
///
|
///
|
||||||
/// let pk = |s| PublicKey::from_str(s).unwrap();
|
/// let pk = |s: &str| s.parse::<PublicKey>().unwrap();
|
||||||
///
|
///
|
||||||
/// let mut unsorted = [
|
/// let mut unsorted = [
|
||||||
/// pk("04c4b0bbb339aa236bff38dbe6a451e111972a7909a126bc424013cba2ec33bc38e98ac269ffe028345c31ac8d0a365f29c8f7e7cfccac72f84e1acd02bc554f35"),
|
/// pk("04c4b0bbb339aa236bff38dbe6a451e111972a7909a126bc424013cba2ec33bc38e98ac269ffe028345c31ac8d0a365f29c8f7e7cfccac72f84e1acd02bc554f35"),
|
||||||
|
|
|
@ -37,15 +37,14 @@ use arbitrary::{Arbitrary, Unstructured};
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use core::str::FromStr;
|
|
||||||
/// # use bitcoin_units::Amount;
|
/// # use bitcoin_units::Amount;
|
||||||
///
|
///
|
||||||
/// assert_eq!(Amount::from_str("1 BTC").unwrap(), Amount::from_sat(100_000_000));
|
/// assert_eq!("1 BTC".parse::<Amount>().unwrap(), Amount::from_sat(100_000_000));
|
||||||
/// assert_eq!(Amount::from_str("1 cBTC").unwrap(), Amount::from_sat(1_000_000));
|
/// assert_eq!("1 cBTC".parse::<Amount>().unwrap(), Amount::from_sat(1_000_000));
|
||||||
/// assert_eq!(Amount::from_str("1 mBTC").unwrap(), Amount::from_sat(100_000));
|
/// assert_eq!("1 mBTC".parse::<Amount>().unwrap(), Amount::from_sat(100_000));
|
||||||
/// assert_eq!(Amount::from_str("1 uBTC").unwrap(), Amount::from_sat(100));
|
/// assert_eq!("1 uBTC".parse::<Amount>().unwrap(), Amount::from_sat(100));
|
||||||
/// assert_eq!(Amount::from_str("1 bit").unwrap(), Amount::from_sat(100));
|
/// assert_eq!("1 bit".parse::<Amount>().unwrap(), Amount::from_sat(100));
|
||||||
/// assert_eq!(Amount::from_str("1 sat").unwrap(), Amount::from_sat(1));
|
/// assert_eq!("1 sat".parse::<Amount>().unwrap(), Amount::from_sat(1));
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
|
|
Loading…
Reference in New Issue