Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update rustfmt config to match substrate #570

Merged
merged 3 commits into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
toolchain: nightly
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
Expand Down
8 changes: 3 additions & 5 deletions ethbloom/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//!
//! ```
//! use hex_literal::hex;
//! use ethbloom::{Bloom, Input};
Expand Down Expand Up @@ -46,7 +45,6 @@
//! assert!(my_bloom.contains_input(Input::Raw(&topic)));
//! assert_eq!(my_bloom, bloom);
//! ```
//!

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

Expand Down Expand Up @@ -80,7 +78,7 @@ impl_fixed_hash_codec!(Bloom, BLOOM_SIZE);
/// Returns log2.
fn log2(x: usize) -> u32 {
if x <= 1 {
return 0;
return 0
}

let n = x.leading_zeros();
Expand All @@ -106,7 +104,7 @@ impl<'a> From<Input<'a>> for Hash<'a> {
keccak256.update(raw);
keccak256.finalize(&mut out);
Hash::Owned(out)
}
},
Input::Hash(hash) => Hash::Ref(hash),
}
}
Expand Down Expand Up @@ -248,7 +246,7 @@ impl<'a> BloomRef<'a> {
let a = self.0[i];
let b = bloom_ref.0[i];
if (a & b) != b {
return false;
return false
}
}
true
Expand Down
7 changes: 4 additions & 3 deletions ethereum-types/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ impl_fixed_hash_serde!(H128, 16);
#[cfg(feature = "codec")]
impl_fixed_hash_codec!(H128, 16);

pub use primitive_types::H160;
pub use primitive_types::H256;
pub use primitive_types::{H160, H256};

construct_fixed_hash! { pub struct H264(33); }
#[cfg(feature = "rlp")]
Expand Down Expand Up @@ -136,7 +135,9 @@ mod tests {

#[test]
fn test_parse_0x() {
assert!("0x0000000000000000000000000000000000000000000000000000000000000000".parse::<H256>().is_ok())
assert!("0x0000000000000000000000000000000000000000000000000000000000000000"
.parse::<H256>()
.is_ok())
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions fixed-hash/benches/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

//! Benchmarks for fixed-hash cmp implementation.

use criterion::{black_box, Criterion, ParameterizedBenchmark};
use criterion::{criterion_group, criterion_main};
use criterion::{black_box, criterion_group, criterion_main, Criterion, ParameterizedBenchmark};

use fixed_hash::construct_fixed_hash;

Expand Down
5 changes: 3 additions & 2 deletions fixed-hash/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ macro_rules! impl_rustc_hex_for_fixed_hash {
*byte = iter.next().ok_or(Self::Err::InvalidHexLength)??;
}
if iter.next().is_some() {
return Err(Self::Err::InvalidHexLength);
return Err(Self::Err::InvalidHexLength)
}
Ok(result)
}
Expand Down Expand Up @@ -778,7 +778,8 @@ macro_rules! impl_fixed_hash_conversions {
);

let mut ret = $small_ty::zero();
ret.as_bytes_mut().copy_from_slice(&value[(large_ty_size - small_ty_size)..large_ty_size]);
ret.as_bytes_mut()
.copy_from_slice(&value[(large_ty_size - small_ty_size)..large_ty_size]);
ret
}
}
Expand Down
8 changes: 5 additions & 3 deletions keccak-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub fn keccak_pipe(r: &mut dyn io::BufRead, w: &mut dyn io::Write) -> Result<H25
loop {
let some = r.read(&mut input)?;
if some == 0 {
break;
break
}
keccak256.update(&input[0..some]);
w.write_all(&input[0..some])?;
Expand Down Expand Up @@ -185,8 +185,10 @@ mod tests {
#[cfg(feature = "std")]
#[test]
fn should_keccak_a_file() {
use std::fs;
use std::io::{BufReader, Write};
use std::{
fs,
io::{BufReader, Write},
};

// given
let tmpdir = tempfile::Builder::new().prefix("keccak").tempdir().unwrap();
Expand Down
30 changes: 16 additions & 14 deletions kvdb-memorydb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ impl KeyValueDB for InMemory {
let columns = self.columns.read();
match columns.get(&col) {
None => None,
Some(map) => {
map.iter().find(|&(ref k, _)| k.starts_with(prefix)).map(|(_, v)| v.to_vec().into_boxed_slice())
}
Some(map) => map
.iter()
.find(|&(ref k, _)| k.starts_with(prefix))
.map(|(_, v)| v.to_vec().into_boxed_slice()),
}
}

Expand All @@ -57,34 +58,33 @@ impl KeyValueDB for InMemory {
let ops = transaction.ops;
for op in ops {
match op {
DBOp::Insert { col, key, value } => {
DBOp::Insert { col, key, value } =>
if let Some(col) = columns.get_mut(&col) {
col.insert(key.into_vec(), value);
}
}
DBOp::Delete { col, key } => {
},
DBOp::Delete { col, key } =>
if let Some(col) = columns.get_mut(&col) {
col.remove(&*key);
}
}
DBOp::DeletePrefix { col, prefix } => {
},
DBOp::DeletePrefix { col, prefix } =>
if let Some(col) = columns.get_mut(&col) {
use std::ops::Bound;
if prefix.is_empty() {
col.clear();
} else {
let start_range = Bound::Included(prefix.to_vec());
let keys: Vec<_> = if let Some(end_range) = kvdb::end_prefix(&prefix[..]) {
col.range((start_range, Bound::Excluded(end_range))).map(|(k, _)| k.clone()).collect()
col.range((start_range, Bound::Excluded(end_range)))
.map(|(k, _)| k.clone())
.collect()
} else {
col.range((start_range, Bound::Unbounded)).map(|(k, _)| k.clone()).collect()
};
for key in keys.into_iter() {
col.remove(&key[..]);
}
}
}
}
},
}
}
Ok(())
Expand All @@ -94,7 +94,9 @@ impl KeyValueDB for InMemory {
match self.columns.read().get(&col) {
Some(map) => Box::new(
// TODO: worth optimizing at all?
map.clone().into_iter().map(|(k, v)| (k.into_boxed_slice(), v.into_boxed_slice())),
map.clone()
.into_iter()
.map(|(k, v)| (k.into_boxed_slice(), v.into_boxed_slice())),
),
None => Box::new(None.into_iter()),
}
Expand Down
10 changes: 7 additions & 3 deletions kvdb-rocksdb/benches/bench_read_perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
const NEEDLES: usize = 10_000;
const NEEDLES_TO_HAYSTACK_RATIO: usize = 100;

use std::io;
use std::time::{Duration, Instant};
use std::{
io,
time::{Duration, Instant},
};

use alloc_counter::{count_alloc, AllocCounterSystem};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
Expand Down Expand Up @@ -53,7 +55,9 @@ fn n_random_bytes(n: usize) -> Vec<u8> {
let variability: i64 = rng.gen_range(0..(n / 5) as i64);
let plus_or_minus: i64 = if variability % 2 == 0 { 1 } else { -1 };
let range = Uniform::from(0..u8::max_value());
rng.sample_iter(&range).take((n as i64 + plus_or_minus * variability) as usize).collect()
rng.sample_iter(&range)
.take((n as i64 + plus_or_minus * variability) as usize)
.collect()
}

/// Writes `NEEDLES * NEEDLES_TO_HAYSTACK_RATIO` keys to the DB. Keys are random, 32 bytes long and
Expand Down
9 changes: 7 additions & 2 deletions kvdb-rocksdb/examples/memtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
use ethereum_types::H256;
use keccak_hash::keccak;
use kvdb_rocksdb::{Database, DatabaseConfig};
use std::sync::{atomic::AtomicBool, atomic::Ordering as AtomicOrdering, Arc};
use std::sync::{
atomic::{AtomicBool, Ordering as AtomicOrdering},
Arc,
};
use sysinfo::{get_current_pid, ProcessExt, System, SystemExt};

const COLUMN_COUNT: u32 = 100;
Expand Down Expand Up @@ -67,7 +70,9 @@ fn proc_memory_usage() -> u64 {
let self_pid = get_current_pid().ok();
let memory = if let Some(self_pid) = self_pid {
if sys.refresh_process(self_pid) {
let proc = sys.get_process(self_pid).expect("Above refresh_process succeeds, this should be Some(), qed");
let proc = sys
.get_process(self_pid)
.expect("Above refresh_process succeeds, this should be Some(), qed");
proc.memory()
} else {
0
Expand Down
3 changes: 2 additions & 1 deletion kvdb-rocksdb/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl<'a> IterationHandler for &'a DBAndColumns {
}

fn iter_with_prefix(&self, col: u32, prefix: &[u8], read_opts: ReadOptions) -> Self::Iterator {
self.db.iterator_cf_opt(self.cf(col as usize), read_opts, IteratorMode::From(prefix, Direction::Forward))
self.db
.iterator_cf_opt(self.cf(col as usize), read_opts, IteratorMode::From(prefix, Direction::Forward))
}
}
Loading