Skip to content

Commit 854b310

Browse files
committed
Enable formatter for "src"
Remove the ignore for the "src" directory, this enables the formatter for all source files in the `src/` directory.
1 parent b5c641f commit 854b310

File tree

6 files changed

+88
-99
lines changed

6 files changed

+88
-99
lines changed

rustfmt.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Eventually this shoud be: ignore = []
22
ignore = [
3-
"src",
43
"src/blockdata",
54
"src/consensus",
65
"src/network",

src/hash_types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! hash).
1010
//!
1111
12+
#[rustfmt::skip]
1213
macro_rules! impl_hashencode {
1314
($hashtype:ident) => {
1415
impl $crate::consensus::Encodable for $hashtype {
@@ -23,7 +24,7 @@ macro_rules! impl_hashencode {
2324
Ok(Self::from_inner(<<$hashtype as $crate::hashes::Hash>::Inner>::consensus_decode(r)?))
2425
}
2526
}
26-
}
27+
};
2728
}
2829

2930
// newtypes module is solely here so we can rustfmt::skip.

src/internal_macros.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@ macro_rules! impl_array_newtype {
100100
type Output = <[$ty] as core::ops::Index<I>>::Output;
101101

102102
#[inline]
103-
fn index(&self, index: I) -> &Self::Output {
104-
&self.0[index]
105-
}
103+
fn index(&self, index: I) -> &Self::Output { &self.0[index] }
106104
}
107-
}
105+
};
108106
}
109107

110108
macro_rules! display_from_debug {
@@ -114,7 +112,7 @@ macro_rules! display_from_debug {
114112
core::fmt::Debug::fmt(self, f)
115113
}
116114
}
117-
}
115+
};
118116
}
119117

120118
#[cfg(test)]
@@ -352,8 +350,7 @@ macro_rules! serde_struct_human_string_impl {
352350
/// - core::str::FromStr
353351
/// - hashes::hex::FromHex
354352
macro_rules! impl_bytes_newtype {
355-
($t:ident, $len:literal) => (
356-
353+
($t:ident, $len:literal) => {
357354
impl core::fmt::LowerHex for $t {
358355
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
359356
for &ch in self.0.iter() {
@@ -378,9 +375,9 @@ macro_rules! impl_bytes_newtype {
378375
impl $crate::hashes::hex::FromHex for $t {
379376
fn from_byte_iter<I>(iter: I) -> Result<Self, $crate::hashes::hex::Error>
380377
where
381-
I: core::iter::Iterator<Item=Result<u8, $crate::hashes::hex::Error>>
382-
+ core::iter::ExactSizeIterator
383-
+ core::iter::DoubleEndedIterator,
378+
I: core::iter::Iterator<Item = Result<u8, $crate::hashes::hex::Error>>
379+
+ core::iter::ExactSizeIterator
380+
+ core::iter::DoubleEndedIterator,
384381
{
385382
if iter.len() == $len {
386383
let mut ret = [0; $len];
@@ -477,7 +474,7 @@ macro_rules! impl_bytes_newtype {
477474
}
478475
}
479476
}
480-
)
477+
};
481478
}
482479

483480
macro_rules! user_enum {
@@ -588,9 +585,7 @@ macro_rules! write_err {
588585

589586
/// Asserts a boolean expression at compile time.
590587
macro_rules! const_assert {
591-
($x:expr) => {
592-
{
593-
const _: [(); 0 - !$x as usize] = [];
594-
}
595-
};
588+
($x:expr) => {{
589+
const _: [(); 0 - !$x as usize] = [];
590+
}};
596591
}

src/lib.rs

Lines changed: 48 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@
2929
//!
3030
3131
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
32-
3332
// Experimental features we need.
3433
#![cfg_attr(bench, feature(test))]
3534
#![cfg_attr(docsrs, feature(doc_cfg))]
36-
3735
// Coding conventions
3836
#![forbid(unsafe_code)]
3937
#![deny(non_upper_case_globals)]
@@ -55,7 +53,8 @@ compile_error!(
5553
know if you want 16-bit support. Note that we do NOT guarantee that we will implement it!"
5654
);
5755

58-
#[cfg(bench)] extern crate test;
56+
#[cfg(bench)]
57+
extern crate test;
5958

6059
#[cfg(feature = "no-std")]
6160
#[macro_use]
@@ -64,9 +63,10 @@ extern crate alloc;
6463
extern crate core2;
6564

6665
// Re-exported dependencies.
67-
#[macro_use] pub extern crate bitcoin_hashes as hashes;
68-
pub extern crate secp256k1;
66+
#[macro_use]
67+
pub extern crate bitcoin_hashes as hashes;
6968
pub extern crate bech32;
69+
pub extern crate secp256k1;
7070

7171
#[cfg(feature = "no-std")]
7272
extern crate hashbrown;
@@ -75,12 +75,19 @@ extern crate hashbrown;
7575
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
7676
pub extern crate base64;
7777

78-
#[cfg(feature="bitcoinconsensus")] extern crate bitcoinconsensus;
79-
#[cfg(feature = "serde")] #[macro_use] extern crate actual_serde as serde;
80-
#[cfg(all(test, feature = "serde"))] extern crate serde_json;
81-
#[cfg(all(test, feature = "serde"))] extern crate serde_test;
82-
#[cfg(all(test, feature = "serde"))] extern crate bincode;
83-
#[cfg(all(test, feature = "unstable"))] extern crate test;
78+
#[cfg(feature = "bitcoinconsensus")]
79+
extern crate bitcoinconsensus;
80+
#[cfg(feature = "serde")]
81+
#[macro_use]
82+
extern crate actual_serde as serde;
83+
#[cfg(all(test, feature = "serde"))]
84+
extern crate bincode;
85+
#[cfg(all(test, feature = "serde"))]
86+
extern crate serde_json;
87+
#[cfg(all(test, feature = "serde"))]
88+
extern crate serde_test;
89+
#[cfg(all(test, feature = "unstable"))]
90+
extern crate test;
8491

8592
#[cfg(test)]
8693
#[macro_use]
@@ -93,44 +100,36 @@ mod serde_utils;
93100
#[macro_use]
94101
pub mod network;
95102
pub mod blockdata;
96-
pub mod util;
97103
pub mod consensus;
98104
pub mod hash_types;
99105
pub mod policy;
106+
pub mod util;
100107

101-
pub use crate::hash_types::*;
102-
pub use crate::blockdata::block::Block;
103-
pub use crate::blockdata::block::BlockHeader;
108+
#[cfg(feature = "std")]
109+
use std::io;
110+
111+
#[cfg(not(feature = "std"))]
112+
use core2::io;
113+
114+
pub use crate::blockdata::block::{Block, BlockHeader};
104115
pub use crate::blockdata::script::Script;
105-
pub use crate::blockdata::transaction::Transaction;
106-
pub use crate::blockdata::transaction::TxIn;
107-
pub use crate::blockdata::transaction::Sequence;
108-
pub use crate::blockdata::transaction::TxOut;
109-
pub use crate::blockdata::transaction::OutPoint;
110-
pub use crate::blockdata::transaction::EcdsaSighashType;
116+
#[allow(deprecated)]
117+
pub use crate::blockdata::transaction::SigHashType;
118+
pub use crate::blockdata::transaction::{
119+
EcdsaSighashType, OutPoint, Sequence, Transaction, TxIn, TxOut,
120+
};
111121
pub use crate::blockdata::witness::Witness;
112122
pub use crate::consensus::encode::VarInt;
123+
pub use crate::hash_types::*;
113124
pub use crate::network::constants::Network;
114-
pub use crate::util::Error;
115-
pub use crate::util::address::Address;
116-
pub use crate::util::address::AddressType;
117-
pub use crate::util::amount::Amount;
118-
pub use crate::util::amount::Denomination;
119-
pub use crate::util::amount::SignedAmount;
120-
pub use crate::util::merkleblock::MerkleBlock;
121-
pub use crate::util::sighash::SchnorrSighashType;
122-
125+
pub use crate::util::address::{Address, AddressType};
126+
pub use crate::util::amount::{Amount, Denomination, SignedAmount};
123127
pub use crate::util::ecdsa::{self, EcdsaSig, EcdsaSigError};
128+
pub use crate::util::key::{KeyPair, PrivateKey, PublicKey, XOnlyPublicKey};
129+
pub use crate::util::merkleblock::MerkleBlock;
124130
pub use crate::util::schnorr::{self, SchnorrSig, SchnorrSigError};
125-
pub use crate::util::key::{PrivateKey, PublicKey, XOnlyPublicKey, KeyPair};
126-
pub use crate::util::psbt;
127-
#[allow(deprecated)]
128-
pub use crate::blockdata::transaction::SigHashType;
129-
130-
#[cfg(feature = "std")]
131-
use std::io;
132-
#[cfg(not(feature = "std"))]
133-
use core2::io;
131+
pub use crate::util::sighash::SchnorrSighashType;
132+
pub use crate::util::{psbt, Error};
134133

135134
#[cfg(not(feature = "std"))]
136135
mod io_extras {
@@ -140,20 +139,14 @@ mod io_extras {
140139
}
141140

142141
/// Creates an instance of a writer which will successfully consume all data.
143-
pub const fn sink() -> Sink {
144-
Sink { _priv: () }
145-
}
142+
pub const fn sink() -> Sink { Sink { _priv: () } }
146143

147144
impl core2::io::Write for Sink {
148145
#[inline]
149-
fn write(&mut self, buf: &[u8]) -> core2::io::Result<usize> {
150-
Ok(buf.len())
151-
}
146+
fn write(&mut self, buf: &[u8]) -> core2::io::Result<usize> { Ok(buf.len()) }
152147

153148
#[inline]
154-
fn flush(&mut self) -> core2::io::Result<()> {
155-
Ok(())
156-
}
149+
fn flush(&mut self) -> core2::io::Result<()> { Ok(()) }
157150
}
158151
}
159152

@@ -184,32 +177,26 @@ mod prelude {
184177
pub use std::collections::HashSet;
185178
}
186179

187-
#[cfg(bench)] use bench::EmptyWrite;
180+
#[cfg(bench)]
181+
use bench::EmptyWrite;
188182

189183
#[cfg(bench)]
190184
mod bench {
191185
use core::fmt::Arguments;
186+
192187
use crate::io::{IoSlice, Result, Write};
193188

194189
#[derive(Default, Clone, Debug, PartialEq, Eq)]
195190
pub struct EmptyWrite;
196191

197192
impl Write for EmptyWrite {
198-
fn write(&mut self, buf: &[u8]) -> Result<usize> {
199-
Ok(buf.len())
200-
}
193+
fn write(&mut self, buf: &[u8]) -> Result<usize> { Ok(buf.len()) }
201194
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize> {
202195
Ok(bufs.iter().map(|s| s.len()).sum())
203196
}
204-
fn flush(&mut self) -> Result<()> {
205-
Ok(())
206-
}
197+
fn flush(&mut self) -> Result<()> { Ok(()) }
207198

208-
fn write_all(&mut self, _: &[u8]) -> Result<()> {
209-
Ok(())
210-
}
211-
fn write_fmt(&mut self, _: Arguments) -> Result<()> {
212-
Ok(())
213-
}
199+
fn write_all(&mut self, _: &[u8]) -> Result<()> { Ok(()) }
200+
fn write_fmt(&mut self, _: Arguments) -> Result<()> { Ok(()) }
214201
}
215202
}

src/policy.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
//! These values were taken from bitcoind v0.21.1 (194b9b8792d9b0798fdb570b79fa51f1d1f5ebaf).
1414
//!
1515
16-
use super::blockdata::constants::{MAX_BLOCK_SIGOPS_COST, WITNESS_SCALE_FACTOR};
1716
use core::cmp;
1817

18+
use super::blockdata::constants::{MAX_BLOCK_SIGOPS_COST, WITNESS_SCALE_FACTOR};
19+
1920
/// Maximum weight of a transaction for it to be relayed by most nodes on the network
2021
pub const MAX_STANDARD_TX_WEIGHT: u32 = 400_000;
2122

0 commit comments

Comments
 (0)