Merge rust-bitcoin/rust-bitcoin#3040: Automated nightly rustfmt (2024-07-14)
d57ca72ed0
2024-07-14 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: apoelstra: ACKd57ca72ed0
Tree-SHA512: 3f9d1718c485cdcaa0c03fab3e86e5a0f5534ec3164f3d25c7b4d9b1db7374edf534bb2436da615c1f6432dbbc692b37ca400b309b732170c8cf01ee4482d18f
This commit is contained in:
commit
752f54797a
|
@ -36,9 +36,9 @@ pub use alloc::{string::String, vec::Vec};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::{string::String, vec::Vec};
|
pub use std::{string::String, vec::Vec};
|
||||||
use internals::array_vec::ArrayVec;
|
|
||||||
|
|
||||||
use hashes::sha256d;
|
use hashes::sha256d;
|
||||||
|
use internals::array_vec::ArrayVec;
|
||||||
|
|
||||||
use crate::error::{IncorrectChecksumError, TooShortError};
|
use crate::error::{IncorrectChecksumError, TooShortError};
|
||||||
|
|
||||||
|
@ -127,10 +127,15 @@ pub fn encode(data: &[u8]) -> String {
|
||||||
let reserve_len = encoded_reserve_len(data.len());
|
let reserve_len = encoded_reserve_len(data.len());
|
||||||
let mut res = String::with_capacity(reserve_len);
|
let mut res = String::with_capacity(reserve_len);
|
||||||
if reserve_len <= SHORT_OPT_BUFFER_LEN {
|
if reserve_len <= SHORT_OPT_BUFFER_LEN {
|
||||||
format_iter(&mut res, data.iter().copied(), &mut ArrayVec::<u8, SHORT_OPT_BUFFER_LEN>::new())
|
format_iter(
|
||||||
|
&mut res,
|
||||||
|
data.iter().copied(),
|
||||||
|
&mut ArrayVec::<u8, SHORT_OPT_BUFFER_LEN>::new(),
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
format_iter(&mut res, data.iter().copied(), &mut Vec::with_capacity(reserve_len))
|
format_iter(&mut res, data.iter().copied(), &mut Vec::with_capacity(reserve_len))
|
||||||
}.expect("string doesn't error");
|
}
|
||||||
|
.expect("string doesn't error");
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,34 +184,21 @@ trait Buffer: Sized {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Buffer for Vec<u8> {
|
impl Buffer for Vec<u8> {
|
||||||
fn push(&mut self, val: u8) {
|
fn push(&mut self, val: u8) { Vec::push(self, val) }
|
||||||
Vec::push(self, val)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn slice(&self) -> &[u8] {
|
fn slice(&self) -> &[u8] { self }
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn slice_mut(&mut self) -> &mut [u8] {
|
fn slice_mut(&mut self) -> &mut [u8] { self }
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<const N: usize> Buffer for ArrayVec<u8, N> {
|
impl<const N: usize> Buffer for ArrayVec<u8, N> {
|
||||||
fn push(&mut self, val: u8) {
|
fn push(&mut self, val: u8) { ArrayVec::push(self, val) }
|
||||||
ArrayVec::push(self, val)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn slice(&self) -> &[u8] {
|
fn slice(&self) -> &[u8] { self.as_slice() }
|
||||||
self.as_slice()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn slice_mut(&mut self) -> &mut [u8] {
|
fn slice_mut(&mut self) -> &mut [u8] { self.as_mut_slice() }
|
||||||
self.as_mut_slice()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn format_iter<I, W>(writer: &mut W, data: I, buf: &mut impl Buffer) -> Result<(), fmt::Error>
|
fn format_iter<I, W>(writer: &mut W, data: I, buf: &mut impl Buffer) -> Result<(), fmt::Error>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = u8> + Clone,
|
I: Iterator<Item = u8> + Clone,
|
||||||
|
|
|
@ -465,9 +465,7 @@ impl Witness {
|
||||||
/// This does not guarantee that this represents a P2WS [`Witness`]. See
|
/// This does not guarantee that this represents a P2WS [`Witness`]. See
|
||||||
/// [Script::is_p2wsh](crate::blockdata::script::Script::is_p2wsh) to
|
/// [Script::is_p2wsh](crate::blockdata::script::Script::is_p2wsh) to
|
||||||
/// check whether this is actually a P2WSH witness.
|
/// check whether this is actually a P2WSH witness.
|
||||||
pub fn witness_script(&self) -> Option<&Script> {
|
pub fn witness_script(&self) -> Option<&Script> { self.last().map(Script::from_bytes) }
|
||||||
self.last().map(Script::from_bytes)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Index<usize> for Witness {
|
impl Index<usize> for Witness {
|
||||||
|
|
Loading…
Reference in New Issue