Skip to content

Commit

Permalink
Enable formatter for "src"
Browse files Browse the repository at this point in the history
Remove the ignore for the "src" directory, this enables the formatter
for all source files in the `src/` directory.
  • Loading branch information
tcharding committed Jun 6, 2022
1 parent 9d04228 commit 0f779e1
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 99 deletions.
1 change: 0 additions & 1 deletion rustfmt.toml
@@ -1,6 +1,5 @@
# Eventually this shoud be: ignore = []
ignore = [
"src",
"src/blockdata",
"src/consensus",
"src/network",
Expand Down
15 changes: 11 additions & 4 deletions src/hash_types.rs
Expand Up @@ -23,18 +23,25 @@
macro_rules! impl_hashencode {
($hashtype:ident) => {
impl $crate::consensus::Encodable for $hashtype {
fn consensus_encode<S: $crate::io::Write>(&self, s: S) -> Result<usize, $crate::io::Error> {
fn consensus_encode<S: $crate::io::Write>(
&self,
s: S,
) -> Result<usize, $crate::io::Error> {
self.0.consensus_encode(s)
}
}

impl $crate::consensus::Decodable for $hashtype {
fn consensus_decode<D: $crate::io::Read>(d: D) -> Result<Self, $crate::consensus::encode::Error> {
fn consensus_decode<D: $crate::io::Read>(
d: D,
) -> Result<Self, $crate::consensus::encode::Error> {
use $crate::hashes::Hash;
Ok(Self::from_inner(<<$hashtype as $crate::hashes::Hash>::Inner>::consensus_decode(d)?))
Ok(Self::from_inner(
<<$hashtype as $crate::hashes::Hash>::Inner>::consensus_decode(d)?,
))
}
}
}
};
}

// newtypes module is solely here so we can rustfmt::skip.
Expand Down
34 changes: 20 additions & 14 deletions src/internal_macros.rs
Expand Up @@ -110,11 +110,9 @@ macro_rules! impl_array_newtype {
type Output = <[$ty] as core::ops::Index<I>>::Output;

#[inline]
fn index(&self, index: I) -> &Self::Output {
&self.0[index]
}
fn index(&self, index: I) -> &Self::Output { &self.0[index] }
}
}
};
}

macro_rules! display_from_debug {
Expand All @@ -124,7 +122,7 @@ macro_rules! display_from_debug {
::core::fmt::Debug::fmt(self, f)
}
}
}
};
}

#[cfg(test)]
Expand Down Expand Up @@ -362,8 +360,7 @@ macro_rules! serde_struct_human_string_impl {
/// - core::str::FromStr
/// - hashes::hex::FromHex
macro_rules! impl_bytes_newtype {
($t:ident, $len:expr) => (

($t:ident, $len:expr) => {
impl ::core::fmt::LowerHex for $t {
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
for &ch in self.0.iter() {
Expand All @@ -388,9 +385,9 @@ macro_rules! impl_bytes_newtype {
impl $crate::hashes::hex::FromHex for $t {
fn from_byte_iter<I>(iter: I) -> Result<Self, $crate::hashes::hex::Error>
where
I: ::core::iter::Iterator<Item=Result<u8, $crate::hashes::hex::Error>>
+ ::core::iter::ExactSizeIterator
+ ::core::iter::DoubleEndedIterator,
I: ::core::iter::Iterator<Item = Result<u8, $crate::hashes::hex::Error>>
+ ::core::iter::ExactSizeIterator
+ ::core::iter::DoubleEndedIterator,
{
if iter.len() == $len {
let mut ret = [0; $len];
Expand Down Expand Up @@ -433,7 +430,10 @@ macro_rules! impl_bytes_newtype {
impl<'de> $crate::serde::de::Visitor<'de> for HexVisitor {
type Value = $t;

fn expecting(&self, formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
fn expecting(
&self,
formatter: &mut ::core::fmt::Formatter,
) -> ::core::fmt::Result {
formatter.write_str("an ASCII hex string")
}

Expand All @@ -444,7 +444,10 @@ macro_rules! impl_bytes_newtype {
if let Ok(hex) = ::core::str::from_utf8(v) {
$crate::hashes::hex::FromHex::from_hex(hex).map_err(E::custom)
} else {
return Err(E::invalid_value($crate::serde::de::Unexpected::Bytes(v), &self));
return Err(E::invalid_value(
$crate::serde::de::Unexpected::Bytes(v),
&self,
));
}
}

Expand All @@ -463,7 +466,10 @@ macro_rules! impl_bytes_newtype {
impl<'de> $crate::serde::de::Visitor<'de> for BytesVisitor {
type Value = $t;

fn expecting(&self, formatter: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
fn expecting(
&self,
formatter: &mut ::core::fmt::Formatter,
) -> ::core::fmt::Result {
formatter.write_str("a bytestring")
}

Expand All @@ -485,7 +491,7 @@ macro_rules! impl_bytes_newtype {
}
}
}
)
};
}

macro_rules! user_enum {
Expand Down
104 changes: 44 additions & 60 deletions src/lib.rs
Expand Up @@ -41,12 +41,9 @@
//!

#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]

// Experimental features we need
#![cfg_attr(all(test, feature = "unstable"), feature(test))]

#![cfg_attr(docsrs, feature(doc_cfg))]

// Coding conventions
#![forbid(unsafe_code)]
#![deny(non_upper_case_globals)]
Expand Down Expand Up @@ -79,9 +76,10 @@ extern crate core2;
extern crate core; // for Rust 1.29 and no-std tests

// Re-exported dependencies.
#[macro_use] pub extern crate bitcoin_hashes as hashes;
pub extern crate secp256k1;
#[macro_use]
pub extern crate bitcoin_hashes as hashes;
pub extern crate bech32;
pub extern crate secp256k1;

#[cfg(feature = "no-std")]
extern crate hashbrown;
Expand All @@ -90,12 +88,19 @@ extern crate hashbrown;
#[cfg_attr(docsrs, doc(cfg(feature = "base64")))]
pub extern crate base64;

#[cfg(feature="bitcoinconsensus")] extern crate bitcoinconsensus;
#[cfg(feature = "serde")] #[macro_use] extern crate actual_serde as serde;
#[cfg(all(test, feature = "serde"))] extern crate serde_json;
#[cfg(all(test, feature = "serde"))] extern crate serde_test;
#[cfg(all(test, feature = "serde"))] extern crate bincode;
#[cfg(all(test, feature = "unstable"))] extern crate test;
#[cfg(feature = "bitcoinconsensus")]
extern crate bitcoinconsensus;
#[cfg(feature = "serde")]
#[macro_use]
extern crate actual_serde as serde;
#[cfg(all(test, feature = "serde"))]
extern crate bincode;
#[cfg(all(test, feature = "serde"))]
extern crate serde_json;
#[cfg(all(test, feature = "serde"))]
extern crate serde_test;
#[cfg(all(test, feature = "unstable"))]
extern crate test;

#[cfg(test)]
#[macro_use]
Expand All @@ -108,43 +113,34 @@ mod serde_utils;
#[macro_use]
pub mod network;
pub mod blockdata;
pub mod util;
pub mod consensus;
pub mod hash_types;
pub mod policy;
pub mod util;

pub use crate::hash_types::*;
pub use crate::blockdata::block::Block;
pub use crate::blockdata::block::BlockHeader;
#[cfg(feature = "std")]
use std::io;

#[cfg(not(feature = "std"))]
use core2::io;

pub use crate::blockdata::block::{Block, BlockHeader};
pub use crate::blockdata::script::Script;
pub use crate::blockdata::transaction::Transaction;
pub use crate::blockdata::transaction::TxIn;
pub use crate::blockdata::transaction::TxOut;
pub use crate::blockdata::transaction::OutPoint;
pub use crate::blockdata::transaction::EcdsaSighashType;
#[allow(deprecated)]
pub use crate::blockdata::transaction::SigHashType;
pub use crate::blockdata::transaction::{EcdsaSighashType, OutPoint, Transaction, TxIn, TxOut};
pub use crate::blockdata::witness::Witness;
pub use crate::consensus::encode::VarInt;
pub use crate::hash_types::*;
pub use crate::network::constants::Network;
pub use crate::util::Error;
pub use crate::util::address::Address;
pub use crate::util::address::AddressType;
pub use crate::util::amount::Amount;
pub use crate::util::amount::Denomination;
pub use crate::util::amount::SignedAmount;
pub use crate::util::merkleblock::MerkleBlock;
pub use crate::util::sighash::SchnorrSighashType;

pub use crate::util::address::{Address, AddressType};
pub use crate::util::amount::{Amount, Denomination, SignedAmount};
pub use crate::util::ecdsa::{self, EcdsaSig, EcdsaSigError};
pub use crate::util::key::{KeyPair, PrivateKey, PublicKey, XOnlyPublicKey};
pub use crate::util::merkleblock::MerkleBlock;
pub use crate::util::schnorr::{self, SchnorrSig, SchnorrSigError};
pub use crate::util::key::{PrivateKey, PublicKey, XOnlyPublicKey, KeyPair};
pub use crate::util::psbt;
#[allow(deprecated)]
pub use crate::blockdata::transaction::SigHashType;

#[cfg(feature = "std")]
use std::io;
#[cfg(not(feature = "std"))]
use core2::io;
pub use crate::util::sighash::SchnorrSighashType;
pub use crate::util::{psbt, Error};

#[cfg(not(feature = "std"))]
mod io_extras {
Expand All @@ -154,20 +150,14 @@ mod io_extras {
}

/// Creates an instance of a writer which will successfully consume all data.
pub const fn sink() -> Sink {
Sink { _priv: () }
}
pub const fn sink() -> Sink { Sink { _priv: () } }

impl core2::io::Write for Sink {
#[inline]
fn write(&mut self, buf: &[u8]) -> core2::io::Result<usize> {
Ok(buf.len())
}
fn write(&mut self, buf: &[u8]) -> core2::io::Result<usize> { Ok(buf.len()) }

#[inline]
fn flush(&mut self) -> core2::io::Result<()> {
Ok(())
}
fn flush(&mut self) -> core2::io::Result<()> { Ok(()) }
}
}

Expand Down Expand Up @@ -198,32 +188,26 @@ mod prelude {
pub use std::collections::HashSet;
}

#[cfg(all(test, feature = "unstable"))] use tests::EmptyWrite;
#[cfg(all(test, feature = "unstable"))]
use tests::EmptyWrite;

#[cfg(all(test, feature = "unstable"))]
mod tests {
use core::fmt::Arguments;

use crate::io::{IoSlice, Result, Write};

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

impl Write for EmptyWrite {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
Ok(buf.len())
}
fn write(&mut self, buf: &[u8]) -> Result<usize> { Ok(buf.len()) }
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize> {
Ok(bufs.iter().map(|s| s.len()).sum())
}
fn flush(&mut self) -> Result<()> {
Ok(())
}
fn flush(&mut self) -> Result<()> { Ok(()) }

fn write_all(&mut self, _: &[u8]) -> Result<()> {
Ok(())
}
fn write_fmt(&mut self, _: Arguments) -> Result<()> {
Ok(())
}
fn write_all(&mut self, _: &[u8]) -> Result<()> { Ok(()) }
fn write_fmt(&mut self, _: Arguments) -> Result<()> { Ok(()) }
}
}
3 changes: 2 additions & 1 deletion src/policy.rs
Expand Up @@ -24,9 +24,10 @@
//! These values were taken from bitcoind v0.21.1 (194b9b8792d9b0798fdb570b79fa51f1d1f5ebaf).
//!

use super::blockdata::constants::{MAX_BLOCK_SIGOPS_COST, WITNESS_SCALE_FACTOR};
use core::cmp;

use super::blockdata::constants::{MAX_BLOCK_SIGOPS_COST, WITNESS_SCALE_FACTOR};

/// Maximum weight of a transaction for it to be relayed by most nodes on the network
pub const MAX_STANDARD_TX_WEIGHT: u32 = 400_000;

Expand Down

0 comments on commit 0f779e1

Please sign in to comment.