2024-07-14 automated rustfmt nightly

This commit is contained in:
Fmt Bot 2024-07-14 01:11:56 +00:00 committed by github-actions[bot]
parent 2fcd65ad97
commit d57ca72ed0
2 changed files with 15 additions and 25 deletions

View File

@ -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,33 +184,20 @@ 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

View File

@ -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 {