From 7a1add13a106b91ef2d82aa2c7d3ad34fed1247f Mon Sep 17 00:00:00 2001 From: Ding Xiang Fei Date: Thu, 24 May 2018 13:32:29 +0800 Subject: [PATCH] Ignore protobuf schema when `rustfmt` is invoked --- .gitignore | 1 + Cargo.toml | 1 + src/lib.rs | 35 +++++++++++++++++++---------------- src/proof.rs | 6 ++---- src/proto/mod.rs | 6 +++++- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 1e7caa9..abc3f23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ Cargo.lock target/ +src/proto/proof.rs diff --git a/Cargo.toml b/Cargo.toml index ece70a0..5e76a05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ categories = ["data-structures", "cryptography"] [dependencies] +cfg-if = "0.1.3" ring = "^0.12.0" protobuf = { version = "1.7.1", optional = true } serde = { version = "^1.0.55", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 3c99fe6..ca7598a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,21 +1,28 @@ -#![deny( - missing_docs, unused_qualifications, missing_debug_implementations, - missing_copy_implementations, trivial_casts, trivial_numeric_casts, unsafe_code, - unstable_features, unused_import_braces -)] +#![deny(missing_docs, unused_qualifications, missing_debug_implementations, + missing_copy_implementations, trivial_casts, trivial_numeric_casts, unsafe_code, + unstable_features, unused_import_braces)] //! *merkle* implements a Merkle Tree in Rust. +#[macro_use] +extern crate cfg_if; extern crate ring; -#[cfg(feature = "serialization-protobuf")] -extern crate protobuf; +cfg_if! { + if #[cfg(feature = "serialization-protobuf")] { + extern crate protobuf; + #[allow(unused_qualifications)] + mod proto; + } +} -#[cfg(feature = "serialization-serde")] -extern crate serde; -#[cfg(feature = "serialization-serde")] -#[macro_use] -extern crate serde_derive; +cfg_if! { + if #[cfg(feature = "serialization-serde")] { + extern crate serde; + #[macro_use] + extern crate serde_derive; + } +} mod merkletree; pub use merkletree::MerkleTree; @@ -29,9 +36,5 @@ pub use hashutils::Hashable; mod tree; pub use tree::{LeavesIntoIterator, LeavesIterator}; -#[cfg(feature = "serialization-protobuf")] -#[allow(unused_qualifications)] -mod proto; - #[cfg(test)] mod tests; diff --git a/src/proof.rs b/src/proof.rs index 854e849..dcde4d9 100644 --- a/src/proof.rs +++ b/src/proof.rs @@ -52,10 +52,8 @@ mod algorithm_serde { mod test { use super::*; - use ring::digest::{ - SHA1 as sha1, SHA256 as sha256, SHA384 as sha384, SHA512 as sha512, - SHA512_256 as sha512_256, - }; + use ring::digest::{SHA1 as sha1, SHA256 as sha256, SHA384 as sha384, SHA512 as sha512, + SHA512_256 as sha512_256}; static SHA1: &Algorithm = &sha1; static SHA256: &Algorithm = &sha256; diff --git a/src/proto/mod.rs b/src/proto/mod.rs index cac5c49..2ac4f01 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -1,4 +1,8 @@ -mod proof; +cfg_if! { + if #[cfg(not(rustfmt))] { + mod proof; + } +} use ring::digest::Algorithm;