diff --git a/consensus_encoding/src/decode/decoders.rs b/consensus_encoding/src/decode/decoders.rs index 0a7e3b716..1ddafa40b 100644 --- a/consensus_encoding/src/decode/decoders.rs +++ b/consensus_encoding/src/decode/decoders.rs @@ -615,13 +615,17 @@ impl CompactSizeDecoder { /// /// The final call to [`CompactSizeDecoder::end`] on this decoder will fail if the /// decoded value exceeds 4,000,000 or won't fit in a `usize`. - pub const fn new() -> Self { Self { buf: internals::array_vec::ArrayVec::new(), limit: MAX_VEC_SIZE } } + pub const fn new() -> Self { + Self { buf: internals::array_vec::ArrayVec::new(), limit: MAX_VEC_SIZE } + } /// Constructs a new compact size decoder with encoded value limited to the provided usize. /// /// The final call to [`CompactSizeDecoder::end`] on this decoder will fail if the /// decoded value exceeds `limit` or won't fit in a `usize`. - pub const fn new_with_limit(limit: usize) -> Self { Self { buf: internals::array_vec::ArrayVec::new(), limit } } + pub const fn new_with_limit(limit: usize) -> Self { + Self { buf: internals::array_vec::ArrayVec::new(), limit } + } } impl Default for CompactSizeDecoder { @@ -698,24 +702,20 @@ impl Decoder for CompactSizeDecoder { // This error is returned if dec_value is outside of the usize range, or // if it is above the given limit. - let make_err = || { - CompactSizeDecoderError( - E::ValueExceedsLimit(LengthPrefixExceedsMaxError { - value: dec_value, - limit: self.limit, - }) - ) + let make_err = || { + CompactSizeDecoderError(E::ValueExceedsLimit(LengthPrefixExceedsMaxError { + value: dec_value, + limit: self.limit, + })) }; - usize::try_from(dec_value) - .map_err(|_| make_err()) - .and_then(|nsize| { - if nsize > self.limit { - Err(make_err()) - } else { - Ok(nsize) - } - }) + usize::try_from(dec_value).map_err(|_| make_err()).and_then(|nsize| { + if nsize > self.limit { + Err(make_err()) + } else { + Ok(nsize) + } + }) } fn read_limit(&self) -> usize { diff --git a/consensus_encoding/src/lib.rs b/consensus_encoding/src/lib.rs index ae9d48476..2f5a315ba 100644 --- a/consensus_encoding/src/lib.rs +++ b/consensus_encoding/src/lib.rs @@ -20,15 +20,14 @@ extern crate std; mod decode; mod encode; -#[cfg(feature = "alloc")] -pub use self::decode::decoders::{ - ByteVecDecoder, ByteVecDecoderError, LengthPrefixExceedsMaxError, - VecDecoder, VecDecoderError, -}; pub use self::decode::decoders::{ ArrayDecoder, CompactSizeDecoder, CompactSizeDecoderError, Decoder2, Decoder2Error, Decoder3, Decoder3Error, Decoder4, Decoder4Error, Decoder6, Decoder6Error, UnexpectedEofError, }; +#[cfg(feature = "alloc")] +pub use self::decode::decoders::{ + ByteVecDecoder, ByteVecDecoderError, LengthPrefixExceedsMaxError, VecDecoder, VecDecoderError, +}; #[cfg(feature = "std")] pub use self::decode::{ decode_from_read, decode_from_read_unbuffered, decode_from_read_unbuffered_with, ReadError, diff --git a/internals/src/serde.rs b/internals/src/serde.rs index eb4abde50..bb52e9ef3 100644 --- a/internals/src/serde.rs +++ b/internals/src/serde.rs @@ -31,7 +31,7 @@ pub trait IntoDeError: Sized { } mod impls { - use super::{IntoDeError, de}; + use super::{de, IntoDeError}; impl IntoDeError for core::convert::Infallible { fn into_de_error(self, _expected: Option<&dyn de::Expected>) -> E { diff --git a/p2p/src/message.rs b/p2p/src/message.rs index ec75a77fe..555c5a385 100644 --- a/p2p/src/message.rs +++ b/p2p/src/message.rs @@ -16,11 +16,11 @@ use core::{cmp, fmt}; use arbitrary::{Arbitrary, Unstructured}; use bitcoin::consensus::encode::{self, Decodable, Encodable, ReadExt, WriteExt}; use bitcoin::merkle_tree::MerkleBlock; -use primitives::{block, transaction}; use encoding; use hashes::sha256d; use internals::ToU64 as _; use io::{self, BufRead, Read, Write}; +use primitives::{block, transaction}; use units::FeeRate; use crate::address::{AddrV2Message, Address}; @@ -1660,10 +1660,10 @@ mod test { use alloc::vec; use std::net::Ipv4Addr; - use primitives::{Block, BlockHash}; use bitcoin::consensus::encode::{deserialize, deserialize_partial, serialize}; - use primitives::transaction::{Transaction, Txid}; use hex_lit::hex; + use primitives::transaction::{Transaction, Txid}; + use primitives::{Block, BlockHash}; use units::BlockHeight; use super::*; diff --git a/p2p/src/message_blockdata.rs b/p2p/src/message_blockdata.rs index a6b25c2c0..3db68a273 100644 --- a/p2p/src/message_blockdata.rs +++ b/p2p/src/message_blockdata.rs @@ -9,10 +9,10 @@ use alloc::vec::Vec; #[cfg(feature = "arbitrary")] use arbitrary::{Arbitrary, Unstructured}; -use primitives::BlockHash; use bitcoin::consensus::encode::{self, Decodable, Encodable}; -use primitives::transaction::{Txid, Wtxid}; use io::{BufRead, Write}; +use primitives::transaction::{Txid, Wtxid}; +use primitives::BlockHash; use crate::consensus::impl_consensus_encoding; use crate::ProtocolVersion; diff --git a/p2p/src/message_filter.rs b/p2p/src/message_filter.rs index 9f740dcea..bed5ea337 100644 --- a/p2p/src/message_filter.rs +++ b/p2p/src/message_filter.rs @@ -8,8 +8,8 @@ use alloc::vec::Vec; #[cfg(feature = "arbitrary")] use arbitrary::{Arbitrary, Unstructured}; -use primitives::BlockHash; use hashes::{sha256d, HashEngine}; +use primitives::BlockHash; use units::BlockHeight; use crate::consensus::impl_consensus_encoding; diff --git a/p2p/src/message_network.rs b/p2p/src/message_network.rs index 5f364a326..7ff700f19 100644 --- a/p2p/src/message_network.rs +++ b/p2p/src/message_network.rs @@ -109,11 +109,17 @@ impl UserAgent { const MAX_USER_AGENT_LEN: usize = 256; fn panic_invalid_chars(agent_str: &str) { - assert!(!agent_str.chars().any(|c| matches!(c, '/' | '(' | ')' | ':')), "user agent configuration cannot contain: / ( ) :"); + assert!( + !agent_str.chars().any(|c| matches!(c, '/' | '(' | ')' | ':')), + "user agent configuration cannot contain: / ( ) :" + ); } fn panic_max_len(agent_str: &str) { - assert!(agent_str.chars().count() <= Self::MAX_USER_AGENT_LEN, "user agent cannot exceed 256 characters."); + assert!( + agent_str.chars().count() <= Self::MAX_USER_AGENT_LEN, + "user agent cannot exceed 256 characters." + ); } /// Builds a new user agent from the lowest level client software. For example: `Satoshi` is /// used by Bitcoin Core. diff --git a/units/src/time.rs b/units/src/time.rs index c93609a63..a16b3906d 100644 --- a/units/src/time.rs +++ b/units/src/time.rs @@ -168,12 +168,12 @@ impl<'a> Arbitrary<'a> for BlockTime { #[cfg(test)] mod tests { - use super::*; - - #[cfg(feature = "encoding")] - use encoding::{Decodable as _, Decoder as _}; #[cfg(all(feature = "encoding", feature = "alloc"))] use encoding::UnexpectedEofError; + #[cfg(feature = "encoding")] + use encoding::{Decodable as _, Decoder as _}; + + use super::*; #[test] fn block_time_round_trip() {