Skip to content

Commit

Permalink
chore(style): fix linting (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
antouhou authored Jan 11, 2024
1 parent ee398bf commit afe123e
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 17 deletions.
4 changes: 0 additions & 4 deletions src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
pub use core::prelude::v1::*;

pub use alloc::borrow::ToOwned;
pub use alloc::boxed::Box;
pub use alloc::string::{String, ToString};
pub use alloc::vec::Vec;

pub use alloc::format;
pub use alloc::vec;

// Those are exported by default in the std prelude in Rust 2021
pub use core::convert::{TryFrom, TryInto};
pub use core::iter::FromIterator;
3 changes: 1 addition & 2 deletions src/proof_serializers/direct_hashes_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl MerkleProofSerializer for DirectHashesOrder {
let slice = bytes
.get(slice_start..slice_end)
.ok_or_else(Error::vec_to_hash_conversion_error)?;
let vec =
Vec::<u8>::try_from(slice).map_err(|_| Error::vec_to_hash_conversion_error())?;
let vec = Vec::from(slice);
match T::Hash::try_from(vec) {
Ok(val) => proof_hashes_slices.push(val),
Err(_) => return Err(Error::vec_to_hash_conversion_error()),
Expand Down
3 changes: 1 addition & 2 deletions src/proof_serializers/reverse_hashes_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ impl MerkleProofSerializer for ReverseHashesOrder {
let slice = bytes
.get(slice_start..slice_end)
.ok_or_else(Error::vec_to_hash_conversion_error)?;
let vec =
Vec::<u8>::try_from(slice).map_err(|_| Error::vec_to_hash_conversion_error())?;
let vec = Vec::from(slice);
match T::Hash::try_from(vec) {
Ok(val) => proof_hashes_slices.push(val),
Err(_) => return Err(Error::vec_to_hash_conversion_error()),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ pub fn to_hex_string<T: Clone + Into<Vec<u8>>>(bytes: &T) -> String {
/// containing the difference. This function preserves the first
/// vector order.
pub fn difference<T: Clone + PartialEq>(a: &[T], b: &[T]) -> Vec<T> {
a.iter().cloned().filter(|x| !b.contains(x)).collect()
a.iter().filter(|&x| !b.contains(x)).cloned().collect()
}
5 changes: 2 additions & 3 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn combine<T: Clone>(active: Vec<T>, rest: Vec<T>, mut combinations: Vec<Vec<T>>
} else {
let mut next = active.clone();

if let Some(first) = rest.get(0) {
if let Some(first) = rest.first() {
next.push(first.clone());
}

Expand Down Expand Up @@ -123,8 +123,7 @@ pub fn setup_proof_test_cases() -> Vec<ProofTestCases> {
.collect();
let merkle_tree = MerkleTree::<Sha256>::from_leaves(&leaves);

let case = ProofTestCases { merkle_tree, cases };
case
ProofTestCases { merkle_tree, cases }
})
.collect()
}
4 changes: 2 additions & 2 deletions tests/merkle_proof_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub mod root {

let leaves_to_prove: Vec<[u8; 32]> = indices_to_prove
.iter()
.map(|i| leaf_hashes.get(*i).unwrap().clone())
.map(|i| *leaf_hashes.get(*i).unwrap())
.collect();

let merkle_tree = MerkleTree::<Sha256>::from_leaves(&test_data.leaf_hashes);
Expand Down Expand Up @@ -173,7 +173,7 @@ pub mod to_bytes {
}

pub mod from_bytes {
use crate::common;

use rs_merkle::{algorithms::Sha256, Error, MerkleProof};

#[test]
Expand Down
6 changes: 3 additions & 3 deletions tests/merkle_tree_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub mod proof {

pub mod commit {
use crate::common;
use rs_merkle::{algorithms::Sha256, Error, Hasher, MerkleTree};
use rs_merkle::{algorithms::Sha256, Hasher, MerkleTree};

#[test]
pub fn should_give_correct_root_after_commit() {
Expand All @@ -78,7 +78,7 @@ pub mod commit {

// Passing empty vec to create an empty tree
let mut merkle_tree = MerkleTree::<Sha256>::from_leaves(&vec);
let merkle_tree2 = MerkleTree::<Sha256>::from_leaves(&leaf_hashes);
let merkle_tree2 = MerkleTree::<Sha256>::from_leaves(leaf_hashes);
// Adding leaves
merkle_tree.append(leaf_hashes.clone().as_mut());
let root = merkle_tree.uncommitted_root_hex();
Expand Down Expand Up @@ -197,7 +197,7 @@ pub mod commit {
}

pub mod rollback {
use crate::common;

use rs_merkle::{algorithms::Sha256, Hasher, MerkleTree};

#[test]
Expand Down

0 comments on commit afe123e

Please sign in to comment.