2023-12-17 automated rustfmt nightly

This commit is contained in:
Fmt Bot 2023-12-17 00:59:05 +00:00 committed by GitHub
parent eadc6a6c9e
commit 5af7727250
16 changed files with 97 additions and 148 deletions

View File

@ -8,7 +8,7 @@ use bitcoin::bip32::{ChildNumber, DerivationPath, Xpriv, Xpub};
use bitcoin::hex::FromHex; use bitcoin::hex::FromHex;
use bitcoin::secp256k1::ffi::types::AlignedType; use bitcoin::secp256k1::ffi::types::AlignedType;
use bitcoin::secp256k1::Secp256k1; use bitcoin::secp256k1::Secp256k1;
use bitcoin::{Network, NetworkKind, CompressedPublicKey}; use bitcoin::{CompressedPublicKey, Network, NetworkKind};
fn main() { fn main() {
// This example derives root xprv from a 32-byte seed, // This example derives root xprv from a 32-byte seed,

View File

@ -39,8 +39,8 @@ use bitcoin::locktime::absolute;
use bitcoin::psbt::{self, Input, Psbt, PsbtSighashType}; use bitcoin::psbt::{self, Input, Psbt, PsbtSighashType};
use bitcoin::secp256k1::{Secp256k1, Signing, Verification}; use bitcoin::secp256k1::{Secp256k1, Signing, Verification};
use bitcoin::{ use bitcoin::{
transaction, Address, Amount, Network, OutPoint, CompressedPublicKey, ScriptBuf, Sequence, Transaction, transaction, Address, Amount, CompressedPublicKey, Network, OutPoint, ScriptBuf, Sequence,
TxIn, TxOut, Witness, Transaction, TxIn, TxOut, Witness,
}; };
type Result<T> = std::result::Result<T, Error>; type Result<T> = std::result::Result<T, Error>;

View File

@ -1,5 +1,7 @@
use bitcoin::hashes::Hash; use bitcoin::hashes::Hash;
use bitcoin::{consensus, ecdsa, sighash, Amount, CompressedPublicKey, Script, ScriptBuf, Transaction}; use bitcoin::{
consensus, ecdsa, sighash, Amount, CompressedPublicKey, Script, ScriptBuf, Transaction,
};
use hex_lit::hex; use hex_lit::hex;
//These are real blockchain transactions examples of computing sighash for: //These are real blockchain transactions examples of computing sighash for:

View File

@ -45,7 +45,9 @@ use crate::blockdata::constants::{
use crate::blockdata::script::witness_program::WitnessProgram; use crate::blockdata::script::witness_program::WitnessProgram;
use crate::blockdata::script::witness_version::WitnessVersion; use crate::blockdata::script::witness_version::WitnessVersion;
use crate::blockdata::script::{self, PushBytesBuf, Script, ScriptBuf, ScriptHash}; use crate::blockdata::script::{self, PushBytesBuf, Script, ScriptBuf, ScriptHash};
use crate::crypto::key::{PubkeyHash, PublicKey, CompressedPublicKey, TweakedPublicKey, UntweakedPublicKey}; use crate::crypto::key::{
CompressedPublicKey, PubkeyHash, PublicKey, TweakedPublicKey, UntweakedPublicKey,
};
use crate::network::{Network, NetworkKind}; use crate::network::{Network, NetworkKind};
use crate::prelude::*; use crate::prelude::*;
use crate::taproot::TapNodeHash; use crate::taproot::TapNodeHash;
@ -390,10 +392,7 @@ impl Address {
/// Creates a witness pay to public key address from a public key. /// Creates a witness pay to public key address from a public key.
/// ///
/// This is the native segwit address type for an output redeemable with a single signature. /// This is the native segwit address type for an output redeemable with a single signature.
pub fn p2wpkh( pub fn p2wpkh(pk: &CompressedPublicKey, network: Network) -> Self {
pk: &CompressedPublicKey,
network: Network,
) -> Self {
let program = WitnessProgram::p2wpkh(pk); let program = WitnessProgram::p2wpkh(pk);
Address::from_witness_program(program, network) Address::from_witness_program(program, network)
} }
@ -401,10 +400,7 @@ impl Address {
/// Creates a pay to script address that embeds a witness pay to public key. /// Creates a pay to script address that embeds a witness pay to public key.
/// ///
/// This is a segwit address type that looks familiar (as p2sh) to legacy clients. /// This is a segwit address type that looks familiar (as p2sh) to legacy clients.
pub fn p2shwpkh( pub fn p2shwpkh(pk: &CompressedPublicKey, network: impl Into<NetworkKind>) -> Address {
pk: &CompressedPublicKey,
network: impl Into<NetworkKind>,
) -> Address {
let builder = script::Builder::new().push_int(0).push_slice(pk.wpubkey_hash()); let builder = script::Builder::new().push_int(0).push_slice(pk.wpubkey_hash());
let script_hash = builder.as_script().script_hash(); let script_hash = builder.as_script().script_hash();
Address::p2sh_from_hash(script_hash, network) Address::p2sh_from_hash(script_hash, network)

View File

@ -19,7 +19,7 @@ use secp256k1::{self, Secp256k1, XOnlyPublicKey};
use serde; use serde;
use crate::base58; use crate::base58;
use crate::crypto::key::{self, Keypair, PrivateKey, CompressedPublicKey}; use crate::crypto::key::{self, CompressedPublicKey, Keypair, PrivateKey};
use crate::internal_macros::impl_bytes_newtype; use crate::internal_macros::impl_bytes_newtype;
use crate::network::NetworkKind; use crate::network::NetworkKind;
use crate::prelude::*; use crate::prelude::*;

View File

@ -420,22 +420,22 @@ impl Script {
fn minimal_non_dust_inner(&self, dust_relay_fee: u64) -> crate::Amount { fn minimal_non_dust_inner(&self, dust_relay_fee: u64) -> crate::Amount {
// This must never be lower than Bitcoin Core's GetDustThreshold() (as of v0.21) as it may // This must never be lower than Bitcoin Core's GetDustThreshold() (as of v0.21) as it may
// otherwise allow users to create transactions which likely can never be broadcast/confirmed. // otherwise allow users to create transactions which likely can never be broadcast/confirmed.
let sats = dust_relay_fee.checked_mul( let sats = dust_relay_fee
if self.is_op_return() { .checked_mul(if self.is_op_return() {
0 0
} else if self.is_witness_program() { } else if self.is_witness_program() {
32 + 4 + 1 + (107 / 4) + 4 + // The spend cost copied from Core 32 + 4 + 1 + (107 / 4) + 4 + // The spend cost copied from Core
8 + // The serialized size of the TxOut's amount field 8 + // The serialized size of the TxOut's amount field
self.consensus_encode(&mut sink()).expect("sinks don't error") as u64 // The serialized size of this script_pubkey self.consensus_encode(&mut sink()).expect("sinks don't error") as u64 // The serialized size of this script_pubkey
} else { } else {
32 + 4 + 1 + 107 + 4 + // The spend cost copied from Core 32 + 4 + 1 + 107 + 4 + // The spend cost copied from Core
8 + // The serialized size of the TxOut's amount field 8 + // The serialized size of the TxOut's amount field
self.consensus_encode(&mut sink()).expect("sinks don't error") as u64 // The serialized size of this script_pubkey self.consensus_encode(&mut sink()).expect("sinks don't error") as u64 // The serialized size of this script_pubkey
} })
).expect("dust_relay_fee or script length should not be absurdly large") / .expect("dust_relay_fee or script length should not be absurdly large")
1000; // divide by 1000 like in Core to get value as it cancels out DEFAULT_MIN_RELAY_TX_FEE / 1000; // divide by 1000 like in Core to get value as it cancels out DEFAULT_MIN_RELAY_TX_FEE
// Note: We ensure the division happens at the end, since Core performs the division at the end. // Note: We ensure the division happens at the end, since Core performs the division at the end.
// This will make sure none of the implicit floor operations mess with the value. // This will make sure none of the implicit floor operations mess with the value.
crate::Amount::from_sat(sats) crate::Amount::from_sat(sats)
} }

View File

@ -6,10 +6,10 @@ use hashes::Hash;
use hex_lit::hex; use hex_lit::hex;
use super::*; use super::*;
use crate::FeeRate;
use crate::blockdata::opcodes; use crate::blockdata::opcodes;
use crate::consensus::encode::{deserialize, serialize}; use crate::consensus::encode::{deserialize, serialize};
use crate::crypto::key::{PubkeyHash, PublicKey, WPubkeyHash, XOnlyPublicKey}; use crate::crypto::key::{PubkeyHash, PublicKey, WPubkeyHash, XOnlyPublicKey};
use crate::FeeRate;
#[test] #[test]
#[rustfmt::skip] #[rustfmt::skip]
@ -651,7 +651,10 @@ fn defult_dust_value_tests() {
let script_p2wpkh = Builder::new().push_int(0).push_slice([42; 20]).into_script(); let script_p2wpkh = Builder::new().push_int(0).push_slice([42; 20]).into_script();
assert!(script_p2wpkh.is_p2wpkh()); assert!(script_p2wpkh.is_p2wpkh());
assert_eq!(script_p2wpkh.minimal_non_dust(), crate::Amount::from_sat(294)); assert_eq!(script_p2wpkh.minimal_non_dust(), crate::Amount::from_sat(294));
assert_eq!(script_p2wpkh.minimal_non_dust_custom(FeeRate::from_sat_per_vb_unchecked(6)), crate::Amount::from_sat(588)); assert_eq!(
script_p2wpkh.minimal_non_dust_custom(FeeRate::from_sat_per_vb_unchecked(6)),
crate::Amount::from_sat(588)
);
let script_p2pkh = Builder::new() let script_p2pkh = Builder::new()
.push_opcode(OP_DUP) .push_opcode(OP_DUP)
@ -662,7 +665,10 @@ fn defult_dust_value_tests() {
.into_script(); .into_script();
assert!(script_p2pkh.is_p2pkh()); assert!(script_p2pkh.is_p2pkh());
assert_eq!(script_p2pkh.minimal_non_dust(), crate::Amount::from_sat(546)); assert_eq!(script_p2pkh.minimal_non_dust(), crate::Amount::from_sat(546));
assert_eq!(script_p2pkh.minimal_non_dust_custom(FeeRate::from_sat_per_vb_unchecked(6)), crate::Amount::from_sat(1092)); assert_eq!(
script_p2pkh.minimal_non_dust_custom(FeeRate::from_sat_per_vb_unchecked(6)),
crate::Amount::from_sat(1092)
);
} }
#[test] #[test]

View File

@ -557,10 +557,7 @@ impl TxOut {
/// ///
/// [`minimal_non_dust_custom`]: TxOut::minimal_non_dust_custom /// [`minimal_non_dust_custom`]: TxOut::minimal_non_dust_custom
pub fn minimal_non_dust(script_pubkey: ScriptBuf) -> Self { pub fn minimal_non_dust(script_pubkey: ScriptBuf) -> Self {
TxOut { TxOut { value: script_pubkey.minimal_non_dust(), script_pubkey }
value: script_pubkey.minimal_non_dust(),
script_pubkey,
}
} }
/// Creates a `TxOut` with given script and the smallest possible `value` that is **not** dust /// Creates a `TxOut` with given script and the smallest possible `value` that is **not** dust
@ -575,10 +572,7 @@ impl TxOut {
/// ///
/// [`minimal_non_dust`]: TxOut::minimal_non_dust /// [`minimal_non_dust`]: TxOut::minimal_non_dust
pub fn minimal_non_dust_custom(script_pubkey: ScriptBuf, dust_relay_fee: FeeRate) -> Self { pub fn minimal_non_dust_custom(script_pubkey: ScriptBuf, dust_relay_fee: FeeRate) -> Self {
TxOut { TxOut { value: script_pubkey.minimal_non_dust_custom(dust_relay_fee), script_pubkey }
value: script_pubkey.minimal_non_dust_custom(dust_relay_fee),
script_pubkey,
}
} }
} }

View File

@ -57,7 +57,8 @@ pub fn verify_script_with_flags<F: Into<u32>>(
spending_tx, spending_tx,
index, index,
flags.into(), flags.into(),
).map_err(BitcoinconsensusError) )
.map_err(BitcoinconsensusError)
} }
/// Verifies that this transaction is able to spend its inputs. /// Verifies that this transaction is able to spend its inputs.

View File

@ -11,9 +11,9 @@ use core::str::FromStr;
use hashes::{hash160, Hash}; use hashes::{hash160, Hash};
use hex::FromHex; use hex::FromHex;
use internals::array_vec::ArrayVec;
use internals::write_err; use internals::write_err;
use io::{Read, Write}; use io::{Read, Write};
use internals::array_vec::ArrayVec;
use crate::crypto::ecdsa; use crate::crypto::ecdsa;
use crate::internal_macros::impl_asref_push_bytes; use crate::internal_macros::impl_asref_push_bytes;
@ -299,9 +299,7 @@ impl CompressedPublicKey {
/// ///
/// Note that this can be used as a sort key to get BIP67-compliant sorting. /// Note that this can be used as a sort key to get BIP67-compliant sorting.
/// That's why this type doesn't have the `to_sort_key` method - it would duplicate this one. /// That's why this type doesn't have the `to_sort_key` method - it would duplicate this one.
pub fn to_bytes(&self) -> [u8; 33] { pub fn to_bytes(&self) -> [u8; 33] { self.0.serialize() }
self.0.serialize()
}
/// Deserialize a public key from a slice /// Deserialize a public key from a slice
pub fn from_slice(data: &[u8]) -> Result<Self, secp256k1::Error> { pub fn from_slice(data: &[u8]) -> Result<Self, secp256k1::Error> {
@ -354,9 +352,7 @@ impl TryFrom<PublicKey> for CompressedPublicKey {
} }
impl From<CompressedPublicKey> for PublicKey { impl From<CompressedPublicKey> for PublicKey {
fn from(value: CompressedPublicKey) -> Self { fn from(value: CompressedPublicKey) -> Self { PublicKey::new(value.0) }
PublicKey::new(value.0)
}
} }
impl From<CompressedPublicKey> for XOnlyPublicKey { impl From<CompressedPublicKey> for XOnlyPublicKey {
@ -379,7 +375,6 @@ impl From<&CompressedPublicKey> for WPubkeyHash {
fn from(key: &CompressedPublicKey) -> Self { key.wpubkey_hash() } fn from(key: &CompressedPublicKey) -> Self { key.wpubkey_hash() }
} }
/// A Bitcoin ECDSA private key /// A Bitcoin ECDSA private key
#[derive(Debug, Copy, Clone, PartialEq, Eq)] #[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct PrivateKey { pub struct PrivateKey {
@ -1284,7 +1279,8 @@ mod tests {
fn private_key_debug_is_obfuscated() { fn private_key_debug_is_obfuscated() {
let sk = let sk =
PrivateKey::from_str("cVt4o7BGAig1UXywgGSmARhxMdzP5qvQsxKkSsc1XEkw3tDTQFpy").unwrap(); PrivateKey::from_str("cVt4o7BGAig1UXywgGSmARhxMdzP5qvQsxKkSsc1XEkw3tDTQFpy").unwrap();
let want = "PrivateKey { compressed: true, network: Test, inner: SecretKey(#32014e414fdce702) }"; let want =
"PrivateKey { compressed: true, network: Test, inner: SecretKey(#32014e414fdce702) }";
let got = format!("{:?}", sk); let got = format!("{:?}", sk);
assert_eq!(got, want) assert_eq!(got, want)
} }

View File

@ -238,7 +238,8 @@ mod tests {
assert_eq!(signature.to_base64(), signature.to_string()); assert_eq!(signature.to_base64(), signature.to_string());
let signature2 = super::MessageSignature::from_str(&signature.to_string()).unwrap(); let signature2 = super::MessageSignature::from_str(&signature.to_string()).unwrap();
let pubkey = signature2.recover_pubkey(&secp, msg_hash) let pubkey = signature2
.recover_pubkey(&secp, msg_hash)
.unwrap() .unwrap()
.try_into() .try_into()
.expect("compressed was set to true"); .expect("compressed was set to true");

View File

@ -6,9 +6,13 @@ use alloc::boxed::Box;
use alloc::vec::Vec; use alloc::vec::Vec;
use core::borrow::{Borrow, BorrowMut}; use core::borrow::{Borrow, BorrowMut};
use super::{TapNodeHash, TaprootError, TaprootBuilderError, TAPROOT_CONTROL_NODE_SIZE, TAPROOT_CONTROL_MAX_NODE_COUNT};
use hashes::Hash; use hashes::Hash;
use super::{
TapNodeHash, TaprootBuilderError, TaprootError, TAPROOT_CONTROL_MAX_NODE_COUNT,
TAPROOT_CONTROL_NODE_SIZE,
};
/// The merkle proof for inclusion of a tree in a taptree hash. /// The merkle proof for inclusion of a tree in a taptree hash.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
@ -169,9 +173,7 @@ impl IntoIterator for TaprootMerkleBranch {
type Item = TapNodeHash; type Item = TapNodeHash;
#[inline] #[inline]
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter { IntoIter(self.0.into_iter()) }
IntoIter(self.0.into_iter())
}
} }
impl<'a> IntoIterator for &'a TaprootMerkleBranch { impl<'a> IntoIterator for &'a TaprootMerkleBranch {
@ -179,9 +181,7 @@ impl<'a> IntoIterator for &'a TaprootMerkleBranch {
type Item = &'a TapNodeHash; type Item = &'a TapNodeHash;
#[inline] #[inline]
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter { self.0.iter() }
self.0.iter()
}
} }
impl<'a> IntoIterator for &'a mut TaprootMerkleBranch { impl<'a> IntoIterator for &'a mut TaprootMerkleBranch {
@ -189,53 +189,39 @@ impl<'a> IntoIterator for &'a mut TaprootMerkleBranch {
type Item = &'a mut TapNodeHash; type Item = &'a mut TapNodeHash;
#[inline] #[inline]
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter { self.0.iter_mut() }
self.0.iter_mut()
}
} }
impl core::ops::Deref for TaprootMerkleBranch { impl core::ops::Deref for TaprootMerkleBranch {
type Target = [TapNodeHash]; type Target = [TapNodeHash];
#[inline] #[inline]
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target { &self.0 }
&self.0
}
} }
impl core::ops::DerefMut for TaprootMerkleBranch { impl core::ops::DerefMut for TaprootMerkleBranch {
#[inline] #[inline]
fn deref_mut(&mut self) -> &mut Self::Target { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
&mut self.0
}
} }
impl AsRef<[TapNodeHash]> for TaprootMerkleBranch { impl AsRef<[TapNodeHash]> for TaprootMerkleBranch {
#[inline] #[inline]
fn as_ref(&self) -> &[TapNodeHash] { fn as_ref(&self) -> &[TapNodeHash] { &self.0 }
&self.0
}
} }
impl AsMut<[TapNodeHash]> for TaprootMerkleBranch { impl AsMut<[TapNodeHash]> for TaprootMerkleBranch {
#[inline] #[inline]
fn as_mut(&mut self) -> &mut [TapNodeHash] { fn as_mut(&mut self) -> &mut [TapNodeHash] { &mut self.0 }
&mut self.0
}
} }
impl Borrow<[TapNodeHash]> for TaprootMerkleBranch { impl Borrow<[TapNodeHash]> for TaprootMerkleBranch {
#[inline] #[inline]
fn borrow(&self) -> &[TapNodeHash] { fn borrow(&self) -> &[TapNodeHash] { &self.0 }
&self.0
}
} }
impl BorrowMut<[TapNodeHash]> for TaprootMerkleBranch { impl BorrowMut<[TapNodeHash]> for TaprootMerkleBranch {
#[inline] #[inline]
fn borrow_mut(&mut self) -> &mut [TapNodeHash] { fn borrow_mut(&mut self) -> &mut [TapNodeHash] { &mut self.0 }
&mut self.0
}
} }
/// Iterator over node hashes within Taproot merkle branch. /// Iterator over node hashes within Taproot merkle branch.
@ -247,56 +233,38 @@ pub struct IntoIter(alloc::vec::IntoIter<TapNodeHash>);
impl IntoIter { impl IntoIter {
/// Returns the remaining items of this iterator as a slice. /// Returns the remaining items of this iterator as a slice.
#[inline] #[inline]
pub fn as_slice(&self) -> &[TapNodeHash] { pub fn as_slice(&self) -> &[TapNodeHash] { self.0.as_slice() }
self.0.as_slice()
}
/// Returns the remaining items of this iterator as a mutable slice. /// Returns the remaining items of this iterator as a mutable slice.
#[inline] #[inline]
pub fn as_mut_slice(&mut self) -> &mut [TapNodeHash] { pub fn as_mut_slice(&mut self) -> &mut [TapNodeHash] { self.0.as_mut_slice() }
self.0.as_mut_slice()
}
} }
impl Iterator for IntoIter { impl Iterator for IntoIter {
type Item = TapNodeHash; type Item = TapNodeHash;
#[inline] #[inline]
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> { self.0.next() }
self.0.next()
}
#[inline] #[inline]
fn size_hint(&self) -> (usize, Option<usize>) { fn size_hint(&self) -> (usize, Option<usize>) { self.0.size_hint() }
self.0.size_hint()
}
#[inline] #[inline]
fn nth(&mut self, n: usize) -> Option<Self::Item> { fn nth(&mut self, n: usize) -> Option<Self::Item> { self.0.nth(n) }
self.0.nth(n)
}
#[inline] #[inline]
fn last(self) -> Option<Self::Item> { fn last(self) -> Option<Self::Item> { self.0.last() }
self.0.last()
}
#[inline] #[inline]
fn count(self) -> usize { fn count(self) -> usize { self.0.count() }
self.0.count()
}
} }
impl DoubleEndedIterator for IntoIter { impl DoubleEndedIterator for IntoIter {
#[inline] #[inline]
fn next_back(&mut self) -> Option<Self::Item> { fn next_back(&mut self) -> Option<Self::Item> { self.0.next_back() }
self.0.next_back()
}
#[inline] #[inline]
fn nth_back(&mut self, n: usize) -> Option<Self::Item> { fn nth_back(&mut self, n: usize) -> Option<Self::Item> { self.0.nth_back(n) }
self.0.nth_back(n)
}
} }
impl ExactSizeIterator for IntoIter {} impl ExactSizeIterator for IntoIter {}

View File

@ -5,8 +5,8 @@
//! This module provides support for taproot tagged hashes. //! This module provides support for taproot tagged hashes.
//! //!
pub mod serialized_signature;
pub mod merkle_branch; pub mod merkle_branch;
pub mod serialized_signature;
use core::cmp::Reverse; use core::cmp::Reverse;
use core::fmt; use core::fmt;

View File

@ -11,6 +11,7 @@ pub use safety_boundary::ArrayVec;
// inside it! // inside it!
mod safety_boundary { mod safety_boundary {
use core::mem::MaybeUninit; use core::mem::MaybeUninit;
use crate::const_tools::cond_const; use crate::const_tools::cond_const;
/// A growable contiguous collection backed by array. /// A growable contiguous collection backed by array.
@ -100,83 +101,67 @@ mod safety_boundary {
/// memcpy. /// memcpy.
#[allow(clippy::non_canonical_clone_impl)] #[allow(clippy::non_canonical_clone_impl)]
impl<T: Copy, const CAP: usize> Clone for ArrayVec<T, CAP> { impl<T: Copy, const CAP: usize> Clone for ArrayVec<T, CAP> {
fn clone(&self) -> Self { fn clone(&self) -> Self { Self::from_slice(self) }
Self::from_slice(self)
}
} }
impl<T: Copy, const CAP: usize> core::ops::Deref for ArrayVec<T, CAP> { impl<T: Copy, const CAP: usize> core::ops::Deref for ArrayVec<T, CAP> {
type Target = [T]; type Target = [T];
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target { self.as_slice() }
self.as_slice()
}
} }
impl<T: Copy, const CAP: usize> core::ops::DerefMut for ArrayVec<T, CAP> { impl<T: Copy, const CAP: usize> core::ops::DerefMut for ArrayVec<T, CAP> {
fn deref_mut(&mut self) -> &mut Self::Target { fn deref_mut(&mut self) -> &mut Self::Target { self.as_mut_slice() }
self.as_mut_slice()
}
} }
impl<T: Copy + Eq, const CAP: usize> Eq for ArrayVec<T, CAP> {} impl<T: Copy + Eq, const CAP: usize> Eq for ArrayVec<T, CAP> {}
impl<T: Copy + PartialEq, const CAP1: usize, const CAP2: usize> PartialEq<ArrayVec<T, CAP2>> for ArrayVec<T, CAP1> { impl<T: Copy + PartialEq, const CAP1: usize, const CAP2: usize> PartialEq<ArrayVec<T, CAP2>>
fn eq(&self, other: &ArrayVec<T, CAP2>) -> bool { for ArrayVec<T, CAP1>
**self == **other {
} fn eq(&self, other: &ArrayVec<T, CAP2>) -> bool { **self == **other }
} }
impl<T: Copy + PartialEq, const CAP: usize> PartialEq<[T]> for ArrayVec<T, CAP> { impl<T: Copy + PartialEq, const CAP: usize> PartialEq<[T]> for ArrayVec<T, CAP> {
fn eq(&self, other: &[T]) -> bool { fn eq(&self, other: &[T]) -> bool { **self == *other }
**self == *other
}
} }
impl<T: Copy + PartialEq, const CAP: usize> PartialEq<ArrayVec<T, CAP>> for [T] { impl<T: Copy + PartialEq, const CAP: usize> PartialEq<ArrayVec<T, CAP>> for [T] {
fn eq(&self, other: &ArrayVec<T, CAP>) -> bool { fn eq(&self, other: &ArrayVec<T, CAP>) -> bool { *self == **other }
*self == **other
}
} }
impl<T: Copy + PartialEq, const CAP: usize, const LEN: usize> PartialEq<[T; LEN]> for ArrayVec<T, CAP> { impl<T: Copy + PartialEq, const CAP: usize, const LEN: usize> PartialEq<[T; LEN]>
fn eq(&self, other: &[T; LEN]) -> bool { for ArrayVec<T, CAP>
**self == *other {
} fn eq(&self, other: &[T; LEN]) -> bool { **self == *other }
} }
impl<T: Copy + PartialEq, const CAP: usize, const LEN: usize> PartialEq<ArrayVec<T, CAP>> for [T; LEN] { impl<T: Copy + PartialEq, const CAP: usize, const LEN: usize> PartialEq<ArrayVec<T, CAP>>
fn eq(&self, other: &ArrayVec<T, CAP>) -> bool { for [T; LEN]
*self == **other {
} fn eq(&self, other: &ArrayVec<T, CAP>) -> bool { *self == **other }
} }
impl<T: Copy + Ord, const CAP: usize> Ord for ArrayVec<T, CAP> { impl<T: Copy + Ord, const CAP: usize> Ord for ArrayVec<T, CAP> {
fn cmp(&self, other: &ArrayVec<T, CAP>) -> core::cmp::Ordering { fn cmp(&self, other: &ArrayVec<T, CAP>) -> core::cmp::Ordering { (**self).cmp(&**other) }
(**self).cmp(&**other)
}
} }
impl<T: Copy + PartialOrd, const CAP1: usize, const CAP2: usize> PartialOrd<ArrayVec<T, CAP2>> for ArrayVec<T, CAP1> { impl<T: Copy + PartialOrd, const CAP1: usize, const CAP2: usize> PartialOrd<ArrayVec<T, CAP2>>
for ArrayVec<T, CAP1>
{
fn partial_cmp(&self, other: &ArrayVec<T, CAP2>) -> Option<core::cmp::Ordering> { fn partial_cmp(&self, other: &ArrayVec<T, CAP2>) -> Option<core::cmp::Ordering> {
(**self).partial_cmp(&**other) (**self).partial_cmp(&**other)
} }
} }
impl<T: Copy + fmt::Debug, const CAP: usize> fmt::Debug for ArrayVec<T, CAP> { impl<T: Copy + fmt::Debug, const CAP: usize> fmt::Debug for ArrayVec<T, CAP> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&**self, f) }
fmt::Debug::fmt(&**self, f)
}
} }
impl<T: Copy + core::hash::Hash, const CAP: usize> core::hash::Hash for ArrayVec<T, CAP> { impl<T: Copy + core::hash::Hash, const CAP: usize> core::hash::Hash for ArrayVec<T, CAP> {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) { fn hash<H: core::hash::Hasher>(&self, state: &mut H) { core::hash::Hash::hash(&**self, state) }
core::hash::Hash::hash(&**self, state)
}
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::ArrayVec; use super::ArrayVec;

View File

@ -23,8 +23,8 @@ extern crate alloc;
mod error; mod error;
mod macros; mod macros;
use core::convert::TryInto;
use core::cmp; use core::cmp;
use core::convert::TryInto;
#[rustfmt::skip] // Keep public re-exports separate. #[rustfmt::skip] // Keep public re-exports separate.
pub use self::error::{Error, ErrorKind}; pub use self::error::{Error, ErrorKind};

View File

@ -940,11 +940,11 @@ impl SignedAmount {
pub fn from_str_in(s: &str, denom: Denomination) -> Result<SignedAmount, ParseAmountError> { pub fn from_str_in(s: &str, denom: Denomination) -> Result<SignedAmount, ParseAmountError> {
match parse_signed_to_satoshi(s, denom)? { match parse_signed_to_satoshi(s, denom)? {
// (negative, amount) // (negative, amount)
(false, sat) if sat > i64::MAX as u64 => Err(ParseAmountError::TooBig), (false, sat) if sat > i64::MAX as u64 => Err(ParseAmountError::TooBig),
(false, sat) => Ok(SignedAmount(sat as i64)), (false, sat) => Ok(SignedAmount(sat as i64)),
(true, sat) if sat == i64::MAX as u64 + 1 => Ok(SignedAmount(i64::MIN)), (true, sat) if sat == i64::MAX as u64 + 1 => Ok(SignedAmount(i64::MIN)),
(true, sat) if sat > i64::MAX as u64 + 1 => Err(ParseAmountError::TooBig), (true, sat) if sat > i64::MAX as u64 + 1 => Err(ParseAmountError::TooBig),
(true, sat) => Ok(SignedAmount(-(sat as i64))), (true, sat) => Ok(SignedAmount(-(sat as i64))),
} }
} }