From 78ea5a1d1bbefad2455baa23860748b028017b5e Mon Sep 17 00:00:00 2001 From: yancy Date: Sat, 20 Jan 2024 17:19:37 +0100 Subject: [PATCH] format: Apply nightly fmt --- bitcoin/src/blockdata/transaction.rs | 10 ++-------- bitcoin/src/consensus/encode.rs | 20 +++++++++++++++----- bitcoin/src/consensus/serde.rs | 4 ++-- bitcoin/src/crypto/sighash.rs | 1 - bitcoin/src/internal_macros.rs | 22 ++++++++++++++++------ bitcoin/src/pow.rs | 12 +++++++++--- bitcoin/src/psbt/map/global.rs | 2 +- internals/src/macros.rs | 5 ++++- 8 files changed, 49 insertions(+), 27 deletions(-) diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs index faf4ad5733..aae4960195 100644 --- a/bitcoin/src/blockdata/transaction.rs +++ b/bitcoin/src/blockdata/transaction.rs @@ -773,7 +773,7 @@ impl Transaction { #[inline] pub fn total_size(&self) -> usize { let mut size: usize = 4; // Serialized length of a u32 for the version number. - let use_segwit = self.use_segwit_serialization(); + let use_segwit = self.use_segwit_serialization(); if use_segwit { size += 2; // 1 byte for the marker and 1 for the flag. @@ -783,13 +783,7 @@ impl Transaction { size += self .input .iter() - .map(|input| { - if use_segwit { - input.total_size() - } else { - input.base_size() - } - }) + .map(|input| if use_segwit { input.total_size() } else { input.base_size() }) .sum::(); size += VarInt::from(self.output.len()).size(); diff --git a/bitcoin/src/consensus/encode.rs b/bitcoin/src/consensus/encode.rs index c4be972576..f7caedadbe 100644 --- a/bitcoin/src/consensus/encode.rs +++ b/bitcoin/src/consensus/encode.rs @@ -20,7 +20,7 @@ use core::{fmt, mem, u32}; use hashes::{sha256, sha256d, Hash}; use internals::write_err; -use io::{Cursor, BufRead, Read, Write}; +use io::{BufRead, Cursor, Read, Write}; use crate::bip152::{PrefilledTransaction, ShortId}; use crate::bip158::{FilterHash, FilterHeader}; @@ -357,13 +357,18 @@ macro_rules! impl_int_encodable { ($ty:ident, $meth_dec:ident, $meth_enc:ident) => { impl Decodable for $ty { #[inline] - fn consensus_decode(r: &mut R) -> core::result::Result { + fn consensus_decode( + r: &mut R, + ) -> core::result::Result { ReadExt::$meth_dec(r) } } impl Encodable for $ty { #[inline] - fn consensus_encode(&self, w: &mut W) -> core::result::Result { + fn consensus_encode( + &self, + w: &mut W, + ) -> core::result::Result { w.$meth_enc(*self)?; Ok(mem::size_of::<$ty>()) } @@ -539,7 +544,9 @@ macro_rules! impl_array { impl Decodable for [u8; $size] { #[inline] - fn consensus_decode(r: &mut R) -> core::result::Result { + fn consensus_decode( + r: &mut R, + ) -> core::result::Result { let mut ret = [0; $size]; r.read_slice(&mut ret)?; Ok(ret) @@ -583,7 +590,10 @@ macro_rules! impl_vec { ($type: ty) => { impl Encodable for Vec<$type> { #[inline] - fn consensus_encode(&self, w: &mut W) -> core::result::Result { + fn consensus_encode( + &self, + w: &mut W, + ) -> core::result::Result { let mut len = 0; len += VarInt(self.len() as u64).consensus_encode(w)?; for c in self.iter() { diff --git a/bitcoin/src/consensus/serde.rs b/bitcoin/src/consensus/serde.rs index 9a8d66cc89..6cbbd9bb60 100644 --- a/bitcoin/src/consensus/serde.rs +++ b/bitcoin/src/consensus/serde.rs @@ -480,11 +480,11 @@ impl>> BufRead for IterReader { self.buf = Some(byte); Ok(core::slice::from_ref(self.buf.as_ref().expect("we've just filled it"))) - }, + } Some(Err(error)) => { self.error = Some(error); Err(io::ErrorKind::Other.into()) - }, + } None => Ok(&[]), } } diff --git a/bitcoin/src/crypto/sighash.rs b/bitcoin/src/crypto/sighash.rs index de1767a461..758a372c05 100644 --- a/bitcoin/src/crypto/sighash.rs +++ b/bitcoin/src/crypto/sighash.rs @@ -1270,7 +1270,6 @@ impl fmt::Display for SegwitV0Error { } } - #[cfg(feature = "std")] impl std::error::Error for SegwitV0Error { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { diff --git a/bitcoin/src/internal_macros.rs b/bitcoin/src/internal_macros.rs index 875a2a6f4b..a51d14a242 100644 --- a/bitcoin/src/internal_macros.rs +++ b/bitcoin/src/internal_macros.rs @@ -99,10 +99,13 @@ macro_rules! impl_bytes_newtype { impl $crate::hex::FromHex for $t { type Err = $crate::hex::HexToArrayError; - fn from_byte_iter(iter: I) -> core::result::Result + fn from_byte_iter( + iter: I, + ) -> core::result::Result where - I: core::iter::Iterator> - + core::iter::ExactSizeIterator + I: core::iter::Iterator< + Item = core::result::Result, + > + core::iter::ExactSizeIterator + core::iter::DoubleEndedIterator, { Ok($t($crate::hex::FromHex::from_byte_iter(iter)?)) @@ -111,12 +114,17 @@ macro_rules! impl_bytes_newtype { impl core::str::FromStr for $t { type Err = $crate::hex::HexToArrayError; - fn from_str(s: &str) -> core::result::Result { $crate::hex::FromHex::from_hex(s) } + fn from_str(s: &str) -> core::result::Result { + $crate::hex::FromHex::from_hex(s) + } } #[cfg(feature = "serde")] impl $crate::serde::Serialize for $t { - fn serialize(&self, s: S) -> core::result::Result { + fn serialize( + &self, + s: S, + ) -> core::result::Result { if s.is_human_readable() { s.collect_str(self) } else { @@ -127,7 +135,9 @@ macro_rules! impl_bytes_newtype { #[cfg(feature = "serde")] impl<'de> $crate::serde::Deserialize<'de> for $t { - fn deserialize>(d: D) -> core::result::Result<$t, D::Error> { + fn deserialize>( + d: D, + ) -> core::result::Result<$t, D::Error> { if d.is_human_readable() { struct HexVisitor; diff --git a/bitcoin/src/pow.rs b/bitcoin/src/pow.rs index 96d7857707..a5cbf93638 100644 --- a/bitcoin/src/pow.rs +++ b/bitcoin/src/pow.rs @@ -44,17 +44,23 @@ macro_rules! do_impl { impl fmt::Display for $ty { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> core::fmt::Result { fmt::Display::fmt(&self.0, f) } + fn fmt(&self, f: &mut fmt::Formatter) -> core::fmt::Result { + fmt::Display::fmt(&self.0, f) + } } impl fmt::LowerHex for $ty { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> core::fmt::Result { fmt::LowerHex::fmt(&self.0, f) } + fn fmt(&self, f: &mut fmt::Formatter) -> core::fmt::Result { + fmt::LowerHex::fmt(&self.0, f) + } } impl fmt::UpperHex for $ty { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> core::fmt::Result { fmt::UpperHex::fmt(&self.0, f) } + fn fmt(&self, f: &mut fmt::Formatter) -> core::fmt::Result { + fmt::UpperHex::fmt(&self.0, f) + } } }; } diff --git a/bitcoin/src/psbt/map/global.rs b/bitcoin/src/psbt/map/global.rs index 8de2ea4b43..f3334c1a0e 100644 --- a/bitcoin/src/psbt/map/global.rs +++ b/bitcoin/src/psbt/map/global.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: CC0-1.0 -use io::{Cursor, BufRead, Read}; +use io::{BufRead, Cursor, Read}; use crate::bip32::{ChildNumber, DerivationPath, Fingerprint, Xpub}; use crate::blockdata::transaction::Transaction; diff --git a/internals/src/macros.rs b/internals/src/macros.rs index 91e60a1c12..434b2dea70 100644 --- a/internals/src/macros.rs +++ b/internals/src/macros.rs @@ -99,7 +99,10 @@ macro_rules! impl_array_newtype { macro_rules! debug_from_display { ($thing:ident) => { impl core::fmt::Debug for $thing { - fn fmt(&self, f: &mut core::fmt::Formatter) -> core::result::Result<(), core::fmt::Error> { + fn fmt( + &self, + f: &mut core::fmt::Formatter, + ) -> core::result::Result<(), core::fmt::Error> { core::fmt::Display::fmt(self, f) } }