Skip to content

Commit

Permalink
format: Apply nightly fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
yancy committed Jan 20, 2024
1 parent 782c2d1 commit 78ea5a1
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 27 deletions.
10 changes: 2 additions & 8 deletions bitcoin/src/blockdata/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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::<usize>();

size += VarInt::from(self.output.len()).size();
Expand Down
20 changes: 15 additions & 5 deletions bitcoin/src/consensus/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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: BufRead + ?Sized>(r: &mut R) -> core::result::Result<Self, Error> {
fn consensus_decode<R: BufRead + ?Sized>(
r: &mut R,
) -> core::result::Result<Self, Error> {
ReadExt::$meth_dec(r)
}
}
impl Encodable for $ty {
#[inline]
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> core::result::Result<usize, io::Error> {
fn consensus_encode<W: Write + ?Sized>(
&self,
w: &mut W,
) -> core::result::Result<usize, io::Error> {
w.$meth_enc(*self)?;
Ok(mem::size_of::<$ty>())
}
Expand Down Expand Up @@ -539,7 +544,9 @@ macro_rules! impl_array {

impl Decodable for [u8; $size] {
#[inline]
fn consensus_decode<R: BufRead + ?Sized>(r: &mut R) -> core::result::Result<Self, Error> {
fn consensus_decode<R: BufRead + ?Sized>(
r: &mut R,
) -> core::result::Result<Self, Error> {
let mut ret = [0; $size];
r.read_slice(&mut ret)?;
Ok(ret)
Expand Down Expand Up @@ -583,7 +590,10 @@ macro_rules! impl_vec {
($type: ty) => {
impl Encodable for Vec<$type> {
#[inline]
fn consensus_encode<W: Write + ?Sized>(&self, w: &mut W) -> core::result::Result<usize, io::Error> {
fn consensus_encode<W: Write + ?Sized>(
&self,
w: &mut W,
) -> core::result::Result<usize, io::Error> {
let mut len = 0;
len += VarInt(self.len() as u64).consensus_encode(w)?;
for c in self.iter() {
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/src/consensus/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,11 @@ impl<E: fmt::Debug, I: Iterator<Item = Result<u8, E>>> BufRead for IterReader<E,
Some(Ok(byte)) => {
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(&[]),
}
}
Expand Down
1 change: 0 additions & 1 deletion bitcoin/src/crypto/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)> {
Expand Down
22 changes: 16 additions & 6 deletions bitcoin/src/internal_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ macro_rules! impl_bytes_newtype {
impl $crate::hex::FromHex for $t {
type Err = $crate::hex::HexToArrayError;

fn from_byte_iter<I>(iter: I) -> core::result::Result<Self, $crate::hex::HexToArrayError>
fn from_byte_iter<I>(
iter: I,
) -> core::result::Result<Self, $crate::hex::HexToArrayError>
where
I: core::iter::Iterator<Item = core::result::Result<u8, $crate::hex::HexToBytesError>>
+ core::iter::ExactSizeIterator
I: core::iter::Iterator<
Item = core::result::Result<u8, $crate::hex::HexToBytesError>,
> + core::iter::ExactSizeIterator
+ core::iter::DoubleEndedIterator,
{
Ok($t($crate::hex::FromHex::from_byte_iter(iter)?))
Expand All @@ -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<Self, Self::Err> { $crate::hex::FromHex::from_hex(s) }
fn from_str(s: &str) -> core::result::Result<Self, Self::Err> {
$crate::hex::FromHex::from_hex(s)
}
}

#[cfg(feature = "serde")]
impl $crate::serde::Serialize for $t {
fn serialize<S: $crate::serde::Serializer>(&self, s: S) -> core::result::Result<S::Ok, S::Error> {
fn serialize<S: $crate::serde::Serializer>(
&self,
s: S,
) -> core::result::Result<S::Ok, S::Error> {
if s.is_human_readable() {
s.collect_str(self)
} else {
Expand All @@ -127,7 +135,9 @@ macro_rules! impl_bytes_newtype {

#[cfg(feature = "serde")]
impl<'de> $crate::serde::Deserialize<'de> for $t {
fn deserialize<D: $crate::serde::Deserializer<'de>>(d: D) -> core::result::Result<$t, D::Error> {
fn deserialize<D: $crate::serde::Deserializer<'de>>(
d: D,
) -> core::result::Result<$t, D::Error> {
if d.is_human_readable() {
struct HexVisitor;

Expand Down
12 changes: 9 additions & 3 deletions bitcoin/src/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
};
}
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/psbt/map/global.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 4 additions & 1 deletion internals/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 78ea5a1

Please sign in to comment.