Merge rust-bitcoin/rust-bitcoin#2298: Automated nightly rustfmt (2023-12-17)
5af7727250
2023-12-17 automated rustfmt nightly (Fmt Bot) Pull request description: Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action ACKs for top commit: Kixunil: ACK5af7727250
apoelstra: ACK5af7727250
Tree-SHA512: f3a4c7e80cc7d30eb10572bf44f3a0cd44748dd4f24a0d9f0fcf7de4f5c351c1dd17cbd80253b074f9fdac7e1bcf4bab7b0fbe61067e9a9dafc4fe5c25f1ab52
This commit is contained in:
commit
4fd88e2f30
|
@ -8,7 +8,7 @@ use bitcoin::bip32::{ChildNumber, DerivationPath, Xpriv, Xpub};
|
|||
use bitcoin::hex::FromHex;
|
||||
use bitcoin::secp256k1::ffi::types::AlignedType;
|
||||
use bitcoin::secp256k1::Secp256k1;
|
||||
use bitcoin::{Network, NetworkKind, CompressedPublicKey};
|
||||
use bitcoin::{CompressedPublicKey, Network, NetworkKind};
|
||||
|
||||
fn main() {
|
||||
// This example derives root xprv from a 32-byte seed,
|
||||
|
|
|
@ -39,8 +39,8 @@ use bitcoin::locktime::absolute;
|
|||
use bitcoin::psbt::{self, Input, Psbt, PsbtSighashType};
|
||||
use bitcoin::secp256k1::{Secp256k1, Signing, Verification};
|
||||
use bitcoin::{
|
||||
transaction, Address, Amount, Network, OutPoint, CompressedPublicKey, ScriptBuf, Sequence, Transaction,
|
||||
TxIn, TxOut, Witness,
|
||||
transaction, Address, Amount, CompressedPublicKey, Network, OutPoint, ScriptBuf, Sequence,
|
||||
Transaction, TxIn, TxOut, Witness,
|
||||
};
|
||||
|
||||
type Result<T> = std::result::Result<T, Error>;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
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;
|
||||
|
||||
//These are real blockchain transactions examples of computing sighash for:
|
||||
|
|
|
@ -45,7 +45,9 @@ use crate::blockdata::constants::{
|
|||
use crate::blockdata::script::witness_program::WitnessProgram;
|
||||
use crate::blockdata::script::witness_version::WitnessVersion;
|
||||
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::prelude::*;
|
||||
use crate::taproot::TapNodeHash;
|
||||
|
@ -390,10 +392,7 @@ impl Address {
|
|||
/// 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.
|
||||
pub fn p2wpkh(
|
||||
pk: &CompressedPublicKey,
|
||||
network: Network,
|
||||
) -> Self {
|
||||
pub fn p2wpkh(pk: &CompressedPublicKey, network: Network) -> Self {
|
||||
let program = WitnessProgram::p2wpkh(pk);
|
||||
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.
|
||||
///
|
||||
/// This is a segwit address type that looks familiar (as p2sh) to legacy clients.
|
||||
pub fn p2shwpkh(
|
||||
pk: &CompressedPublicKey,
|
||||
network: impl Into<NetworkKind>,
|
||||
) -> Address {
|
||||
pub fn p2shwpkh(pk: &CompressedPublicKey, network: impl Into<NetworkKind>) -> Address {
|
||||
let builder = script::Builder::new().push_int(0).push_slice(pk.wpubkey_hash());
|
||||
let script_hash = builder.as_script().script_hash();
|
||||
Address::p2sh_from_hash(script_hash, network)
|
||||
|
|
|
@ -19,7 +19,7 @@ use secp256k1::{self, Secp256k1, XOnlyPublicKey};
|
|||
use serde;
|
||||
|
||||
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::network::NetworkKind;
|
||||
use crate::prelude::*;
|
||||
|
|
|
@ -420,8 +420,8 @@ impl Script {
|
|||
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
|
||||
// otherwise allow users to create transactions which likely can never be broadcast/confirmed.
|
||||
let sats = dust_relay_fee.checked_mul(
|
||||
if self.is_op_return() {
|
||||
let sats = dust_relay_fee
|
||||
.checked_mul(if self.is_op_return() {
|
||||
0
|
||||
} else if self.is_witness_program() {
|
||||
32 + 4 + 1 + (107 / 4) + 4 + // The spend cost copied from Core
|
||||
|
@ -431,9 +431,9 @@ impl Script {
|
|||
32 + 4 + 1 + 107 + 4 + // The spend cost copied from Core
|
||||
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
|
||||
}
|
||||
).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
|
||||
})
|
||||
.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
|
||||
// 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.
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@ use hashes::Hash;
|
|||
use hex_lit::hex;
|
||||
|
||||
use super::*;
|
||||
use crate::FeeRate;
|
||||
use crate::blockdata::opcodes;
|
||||
use crate::consensus::encode::{deserialize, serialize};
|
||||
use crate::crypto::key::{PubkeyHash, PublicKey, WPubkeyHash, XOnlyPublicKey};
|
||||
use crate::FeeRate;
|
||||
|
||||
#[test]
|
||||
#[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();
|
||||
assert!(script_p2wpkh.is_p2wpkh());
|
||||
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()
|
||||
.push_opcode(OP_DUP)
|
||||
|
@ -662,7 +665,10 @@ fn defult_dust_value_tests() {
|
|||
.into_script();
|
||||
assert!(script_p2pkh.is_p2pkh());
|
||||
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]
|
||||
|
|
|
@ -557,10 +557,7 @@ impl TxOut {
|
|||
///
|
||||
/// [`minimal_non_dust_custom`]: TxOut::minimal_non_dust_custom
|
||||
pub fn minimal_non_dust(script_pubkey: ScriptBuf) -> Self {
|
||||
TxOut {
|
||||
value: script_pubkey.minimal_non_dust(),
|
||||
script_pubkey,
|
||||
}
|
||||
TxOut { value: script_pubkey.minimal_non_dust(), script_pubkey }
|
||||
}
|
||||
|
||||
/// 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
|
||||
pub fn minimal_non_dust_custom(script_pubkey: ScriptBuf, dust_relay_fee: FeeRate) -> Self {
|
||||
TxOut {
|
||||
value: script_pubkey.minimal_non_dust_custom(dust_relay_fee),
|
||||
script_pubkey,
|
||||
}
|
||||
TxOut { value: script_pubkey.minimal_non_dust_custom(dust_relay_fee), script_pubkey }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,8 @@ pub fn verify_script_with_flags<F: Into<u32>>(
|
|||
spending_tx,
|
||||
index,
|
||||
flags.into(),
|
||||
).map_err(BitcoinconsensusError)
|
||||
)
|
||||
.map_err(BitcoinconsensusError)
|
||||
}
|
||||
|
||||
/// Verifies that this transaction is able to spend its inputs.
|
||||
|
|
|
@ -11,9 +11,9 @@ use core::str::FromStr;
|
|||
|
||||
use hashes::{hash160, Hash};
|
||||
use hex::FromHex;
|
||||
use internals::array_vec::ArrayVec;
|
||||
use internals::write_err;
|
||||
use io::{Read, Write};
|
||||
use internals::array_vec::ArrayVec;
|
||||
|
||||
use crate::crypto::ecdsa;
|
||||
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.
|
||||
/// 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] {
|
||||
self.0.serialize()
|
||||
}
|
||||
pub fn to_bytes(&self) -> [u8; 33] { self.0.serialize() }
|
||||
|
||||
/// Deserialize a public key from a slice
|
||||
pub fn from_slice(data: &[u8]) -> Result<Self, secp256k1::Error> {
|
||||
|
@ -354,9 +352,7 @@ impl TryFrom<PublicKey> for CompressedPublicKey {
|
|||
}
|
||||
|
||||
impl From<CompressedPublicKey> for PublicKey {
|
||||
fn from(value: CompressedPublicKey) -> Self {
|
||||
PublicKey::new(value.0)
|
||||
}
|
||||
fn from(value: CompressedPublicKey) -> Self { PublicKey::new(value.0) }
|
||||
}
|
||||
|
||||
impl From<CompressedPublicKey> for XOnlyPublicKey {
|
||||
|
@ -379,7 +375,6 @@ impl From<&CompressedPublicKey> for WPubkeyHash {
|
|||
fn from(key: &CompressedPublicKey) -> Self { key.wpubkey_hash() }
|
||||
}
|
||||
|
||||
|
||||
/// A Bitcoin ECDSA private key
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub struct PrivateKey {
|
||||
|
@ -1284,7 +1279,8 @@ mod tests {
|
|||
fn private_key_debug_is_obfuscated() {
|
||||
let sk =
|
||||
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);
|
||||
assert_eq!(got, want)
|
||||
}
|
||||
|
|
|
@ -238,7 +238,8 @@ mod tests {
|
|||
|
||||
assert_eq!(signature.to_base64(), signature.to_string());
|
||||
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()
|
||||
.try_into()
|
||||
.expect("compressed was set to true");
|
||||
|
|
|
@ -6,9 +6,13 @@ use alloc::boxed::Box;
|
|||
use alloc::vec::Vec;
|
||||
use core::borrow::{Borrow, BorrowMut};
|
||||
|
||||
use super::{TapNodeHash, TaprootError, TaprootBuilderError, TAPROOT_CONTROL_NODE_SIZE, TAPROOT_CONTROL_MAX_NODE_COUNT};
|
||||
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.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
|
@ -169,9 +173,7 @@ impl IntoIterator for TaprootMerkleBranch {
|
|||
type Item = TapNodeHash;
|
||||
|
||||
#[inline]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
IntoIter(self.0.into_iter())
|
||||
}
|
||||
fn into_iter(self) -> Self::IntoIter { IntoIter(self.0.into_iter()) }
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a TaprootMerkleBranch {
|
||||
|
@ -179,9 +181,7 @@ impl<'a> IntoIterator for &'a TaprootMerkleBranch {
|
|||
type Item = &'a TapNodeHash;
|
||||
|
||||
#[inline]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.iter()
|
||||
}
|
||||
fn into_iter(self) -> Self::IntoIter { self.0.iter() }
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a mut TaprootMerkleBranch {
|
||||
|
@ -189,53 +189,39 @@ impl<'a> IntoIterator for &'a mut TaprootMerkleBranch {
|
|||
type Item = &'a mut TapNodeHash;
|
||||
|
||||
#[inline]
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.0.iter_mut()
|
||||
}
|
||||
fn into_iter(self) -> Self::IntoIter { self.0.iter_mut() }
|
||||
}
|
||||
|
||||
impl core::ops::Deref for TaprootMerkleBranch {
|
||||
type Target = [TapNodeHash];
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
fn deref(&self) -> &Self::Target { &self.0 }
|
||||
}
|
||||
|
||||
impl core::ops::DerefMut for TaprootMerkleBranch {
|
||||
#[inline]
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.0
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 }
|
||||
}
|
||||
|
||||
impl AsRef<[TapNodeHash]> for TaprootMerkleBranch {
|
||||
#[inline]
|
||||
fn as_ref(&self) -> &[TapNodeHash] {
|
||||
&self.0
|
||||
}
|
||||
fn as_ref(&self) -> &[TapNodeHash] { &self.0 }
|
||||
}
|
||||
|
||||
impl AsMut<[TapNodeHash]> for TaprootMerkleBranch {
|
||||
#[inline]
|
||||
fn as_mut(&mut self) -> &mut [TapNodeHash] {
|
||||
&mut self.0
|
||||
}
|
||||
fn as_mut(&mut self) -> &mut [TapNodeHash] { &mut self.0 }
|
||||
}
|
||||
|
||||
impl Borrow<[TapNodeHash]> for TaprootMerkleBranch {
|
||||
#[inline]
|
||||
fn borrow(&self) -> &[TapNodeHash] {
|
||||
&self.0
|
||||
}
|
||||
fn borrow(&self) -> &[TapNodeHash] { &self.0 }
|
||||
}
|
||||
|
||||
impl BorrowMut<[TapNodeHash]> for TaprootMerkleBranch {
|
||||
#[inline]
|
||||
fn borrow_mut(&mut self) -> &mut [TapNodeHash] {
|
||||
&mut self.0
|
||||
}
|
||||
fn borrow_mut(&mut self) -> &mut [TapNodeHash] { &mut self.0 }
|
||||
}
|
||||
|
||||
/// Iterator over node hashes within Taproot merkle branch.
|
||||
|
@ -247,56 +233,38 @@ pub struct IntoIter(alloc::vec::IntoIter<TapNodeHash>);
|
|||
impl IntoIter {
|
||||
/// Returns the remaining items of this iterator as a slice.
|
||||
#[inline]
|
||||
pub fn as_slice(&self) -> &[TapNodeHash] {
|
||||
self.0.as_slice()
|
||||
}
|
||||
pub fn as_slice(&self) -> &[TapNodeHash] { self.0.as_slice() }
|
||||
|
||||
/// Returns the remaining items of this iterator as a mutable slice.
|
||||
#[inline]
|
||||
pub fn as_mut_slice(&mut self) -> &mut [TapNodeHash] {
|
||||
self.0.as_mut_slice()
|
||||
}
|
||||
pub fn as_mut_slice(&mut self) -> &mut [TapNodeHash] { self.0.as_mut_slice() }
|
||||
}
|
||||
|
||||
impl Iterator for IntoIter {
|
||||
type Item = TapNodeHash;
|
||||
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.0.next()
|
||||
}
|
||||
fn next(&mut self) -> Option<Self::Item> { self.0.next() }
|
||||
|
||||
#[inline]
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.0.size_hint()
|
||||
}
|
||||
fn size_hint(&self) -> (usize, Option<usize>) { self.0.size_hint() }
|
||||
|
||||
#[inline]
|
||||
fn nth(&mut self, n: usize) -> Option<Self::Item> {
|
||||
self.0.nth(n)
|
||||
}
|
||||
fn nth(&mut self, n: usize) -> Option<Self::Item> { self.0.nth(n) }
|
||||
|
||||
#[inline]
|
||||
fn last(self) -> Option<Self::Item> {
|
||||
self.0.last()
|
||||
}
|
||||
fn last(self) -> Option<Self::Item> { self.0.last() }
|
||||
|
||||
#[inline]
|
||||
fn count(self) -> usize {
|
||||
self.0.count()
|
||||
}
|
||||
fn count(self) -> usize { self.0.count() }
|
||||
}
|
||||
|
||||
impl DoubleEndedIterator for IntoIter {
|
||||
#[inline]
|
||||
fn next_back(&mut self) -> Option<Self::Item> {
|
||||
self.0.next_back()
|
||||
}
|
||||
fn next_back(&mut self) -> Option<Self::Item> { self.0.next_back() }
|
||||
|
||||
#[inline]
|
||||
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
|
||||
self.0.nth_back(n)
|
||||
}
|
||||
fn nth_back(&mut self, n: usize) -> Option<Self::Item> { self.0.nth_back(n) }
|
||||
}
|
||||
|
||||
impl ExactSizeIterator for IntoIter {}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
//! This module provides support for taproot tagged hashes.
|
||||
//!
|
||||
|
||||
pub mod serialized_signature;
|
||||
pub mod merkle_branch;
|
||||
pub mod serialized_signature;
|
||||
|
||||
use core::cmp::Reverse;
|
||||
use core::fmt;
|
||||
|
|
|
@ -11,6 +11,7 @@ pub use safety_boundary::ArrayVec;
|
|||
// inside it!
|
||||
mod safety_boundary {
|
||||
use core::mem::MaybeUninit;
|
||||
|
||||
use crate::const_tools::cond_const;
|
||||
|
||||
/// A growable contiguous collection backed by array.
|
||||
|
@ -100,83 +101,67 @@ mod safety_boundary {
|
|||
/// memcpy.
|
||||
#[allow(clippy::non_canonical_clone_impl)]
|
||||
impl<T: Copy, const CAP: usize> Clone for ArrayVec<T, CAP> {
|
||||
fn clone(&self) -> Self {
|
||||
Self::from_slice(self)
|
||||
}
|
||||
fn clone(&self) -> Self { Self::from_slice(self) }
|
||||
}
|
||||
|
||||
|
||||
impl<T: Copy, const CAP: usize> core::ops::Deref for ArrayVec<T, CAP> {
|
||||
type Target = [T];
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.as_slice()
|
||||
}
|
||||
fn deref(&self) -> &Self::Target { self.as_slice() }
|
||||
}
|
||||
|
||||
impl<T: Copy, const CAP: usize> core::ops::DerefMut for ArrayVec<T, CAP> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
self.as_mut_slice()
|
||||
}
|
||||
fn deref_mut(&mut self) -> &mut Self::Target { self.as_mut_slice() }
|
||||
}
|
||||
|
||||
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> {
|
||||
fn eq(&self, other: &ArrayVec<T, CAP2>) -> bool {
|
||||
**self == **other
|
||||
}
|
||||
impl<T: Copy + PartialEq, const CAP1: usize, const CAP2: usize> PartialEq<ArrayVec<T, CAP2>>
|
||||
for ArrayVec<T, CAP1>
|
||||
{
|
||||
fn eq(&self, other: &ArrayVec<T, CAP2>) -> bool { **self == **other }
|
||||
}
|
||||
|
||||
impl<T: Copy + PartialEq, const CAP: usize> PartialEq<[T]> for ArrayVec<T, CAP> {
|
||||
fn eq(&self, other: &[T]) -> bool {
|
||||
**self == *other
|
||||
}
|
||||
fn eq(&self, other: &[T]) -> bool { **self == *other }
|
||||
}
|
||||
|
||||
impl<T: Copy + PartialEq, const CAP: usize> PartialEq<ArrayVec<T, CAP>> for [T] {
|
||||
fn eq(&self, other: &ArrayVec<T, CAP>) -> bool {
|
||||
*self == **other
|
||||
}
|
||||
fn eq(&self, other: &ArrayVec<T, CAP>) -> bool { *self == **other }
|
||||
}
|
||||
|
||||
impl<T: Copy + PartialEq, const CAP: usize, const LEN: usize> PartialEq<[T; LEN]> for ArrayVec<T, CAP> {
|
||||
fn eq(&self, other: &[T; LEN]) -> bool {
|
||||
**self == *other
|
||||
}
|
||||
impl<T: Copy + PartialEq, const CAP: usize, const LEN: usize> PartialEq<[T; LEN]>
|
||||
for ArrayVec<T, CAP>
|
||||
{
|
||||
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] {
|
||||
fn eq(&self, other: &ArrayVec<T, CAP>) -> bool {
|
||||
*self == **other
|
||||
}
|
||||
impl<T: Copy + PartialEq, const CAP: usize, const LEN: usize> PartialEq<ArrayVec<T, CAP>>
|
||||
for [T; LEN]
|
||||
{
|
||||
fn eq(&self, other: &ArrayVec<T, CAP>) -> bool { *self == **other }
|
||||
}
|
||||
|
||||
impl<T: Copy + Ord, const CAP: usize> Ord for ArrayVec<T, CAP> {
|
||||
fn cmp(&self, other: &ArrayVec<T, CAP>) -> core::cmp::Ordering {
|
||||
(**self).cmp(&**other)
|
||||
}
|
||||
fn cmp(&self, other: &ArrayVec<T, CAP>) -> core::cmp::Ordering { (**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> {
|
||||
(**self).partial_cmp(&**other)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Copy + fmt::Debug, const CAP: usize> fmt::Debug for ArrayVec<T, CAP> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::Debug::fmt(&**self, f)
|
||||
}
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&**self, f) }
|
||||
}
|
||||
|
||||
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) {
|
||||
core::hash::Hash::hash(&**self, state)
|
||||
}
|
||||
fn hash<H: core::hash::Hasher>(&self, state: &mut H) { core::hash::Hash::hash(&**self, state) }
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ArrayVec;
|
||||
|
|
|
@ -23,8 +23,8 @@ extern crate alloc;
|
|||
mod error;
|
||||
mod macros;
|
||||
|
||||
use core::convert::TryInto;
|
||||
use core::cmp;
|
||||
use core::convert::TryInto;
|
||||
|
||||
#[rustfmt::skip] // Keep public re-exports separate.
|
||||
pub use self::error::{Error, ErrorKind};
|
||||
|
|
Loading…
Reference in New Issue