From 1e90d113607995bf35aca41c5b07d351b585b00d Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Fri, 1 Jan 2021 16:24:40 +0100 Subject: [PATCH] [style] comply to clippy 1.49 --- rust-bins/duniter-dbex/src/export_bc.rs | 26 +++++++++---------- rust-bins/duniter-dbex/src/main.rs | 1 - rust-bins/duniter-dbex/src/migrate.rs | 6 ++--- .../duniter-dbex/src/print_found_data.rs | 2 +- .../gva/dbs-reader/src/uds_of_pubkey.rs | 5 ++-- rust-libs/modules/gva/src/anti_spam.rs | 3 +-- rust-libs/tools/kv_typed/src/as_bytes.rs | 4 +-- rust-libs/tools/kv_typed/src/from_bytes.rs | 4 +-- rust-libs/tools/kv_typed/src/lib.rs | 1 - .../tools/kv_typed/tests/test_db_schema.rs | 6 ++--- 10 files changed, 26 insertions(+), 32 deletions(-) diff --git a/rust-bins/duniter-dbex/src/export_bc.rs b/rust-bins/duniter-dbex/src/export_bc.rs index 94a9f91b5..007880843 100644 --- a/rust-bins/duniter-dbex/src/export_bc.rs +++ b/rust-bins/duniter-dbex/src/export_bc.rs @@ -55,25 +55,23 @@ pub(crate) fn export_bc<B: Backend>( let (s, r) = flume::unbounded(); let reader_handle = std::thread::spawn(move || { bc_v1.main_blocks().iter(.., |it| { - it.values() - .map(|block_res| s.send(block_res).map_err(|_| anyhow!("fail to send"))) - .collect::<anyhow::Result<()>>() + it.values().try_for_each(|block_res| { + s.send(block_res).map_err(|_| anyhow!("fail to send")) + }) }) }); let (s2, r2) = flume::unbounded(); let jsonifier_handle = std::thread::spawn(move || { - r.iter() - .map(|block_res| { - let json_block_res = match block_res { - Ok(block) => { - serde_json::to_value(&block).map_err(|e| KvError::DeserError(e.into())) - } - Err(e) => Err(e), - }; - s2.send(json_block_res).map_err(|_| anyhow!("fail to send")) - }) - .collect::<anyhow::Result<()>>() + r.iter().try_for_each(|block_res| { + let json_block_res = match block_res { + Ok(block) => { + serde_json::to_value(&block).map_err(|e| KvError::DeserError(e.into())) + } + Err(e) => Err(e), + }; + s2.send(json_block_res).map_err(|_| anyhow!("fail to send")) + }) }); let threadpool = ThreadPool::start(ThreadPoolConfig::default(), ()).into_sync_handler(); diff --git a/rust-bins/duniter-dbex/src/main.rs b/rust-bins/duniter-dbex/src/main.rs index ca55f5d4c..00cf5abcd 100644 --- a/rust-bins/duniter-dbex/src/main.rs +++ b/rust-bins/duniter-dbex/src/main.rs @@ -49,7 +49,6 @@ use std::{ collections::{HashMap, HashSet}, fs::File, io::{stdin, Write}, - iter::FromIterator, time::Instant, }; use structopt::StructOpt; diff --git a/rust-bins/duniter-dbex/src/migrate.rs b/rust-bins/duniter-dbex/src/migrate.rs index d88dfd6bb..e3e613a58 100644 --- a/rust-bins/duniter-dbex/src/migrate.rs +++ b/rust-bins/duniter-dbex/src/migrate.rs @@ -65,9 +65,9 @@ fn migrate_inner( let (s, r) = flume::unbounded(); let reader_handle = std::thread::spawn(move || { duniter_js_db.main_blocks().iter(.., |it| { - it.values() - .map(|block_res| s.send(block_res).map_err(|_| anyhow!("fail to send"))) - .collect::<anyhow::Result<()>>() + it.values().try_for_each(|block_res| { + s.send(block_res).map_err(|_| anyhow!("fail to send")) + }) }) }); let (s2, r2) = flume::unbounded(); diff --git a/rust-bins/duniter-dbex/src/print_found_data.rs b/rust-bins/duniter-dbex/src/print_found_data.rs index 0c600ef0b..35e79d65b 100644 --- a/rust-bins/duniter-dbex/src/print_found_data.rs +++ b/rust-bins/duniter-dbex/src/print_found_data.rs @@ -42,7 +42,7 @@ pub fn print_found_data<W: Write>( } let only_properties_set = if !only_properties.is_empty() { - HashSet::from_iter(only_properties.into_iter()) + only_properties.into_iter().collect() } else { HashSet::with_capacity(0) }; diff --git a/rust-libs/modules/gva/dbs-reader/src/uds_of_pubkey.rs b/rust-libs/modules/gva/dbs-reader/src/uds_of_pubkey.rs index 669d3d5e7..1dc230fb7 100644 --- a/rust-libs/modules/gva/dbs-reader/src/uds_of_pubkey.rs +++ b/rust-libs/modules/gva/dbs-reader/src/uds_of_pubkey.rs @@ -474,14 +474,13 @@ mod tests { use duniter_dbs::smallvec::smallvec as svec; use duniter_dbs::{databases::bc_v2::BcV2DbWritable, SourceAmountValV2, UdIdV2}; use duniter_gva_db::GvaV1DbWritable; - use std::iter::FromIterator; #[test] fn test_filter_blocks_numbers() -> KvResult<()> { let idty = GvaIdtyDbV1 { is_member: true, joins: svec![BlockNumber(26), BlockNumber(51)], - leaves: BTreeSet::from_iter([BlockNumber(32)].iter().copied()), + leaves: [BlockNumber(32)].iter().copied().collect(), first_ud: Some(BlockNumber(29)), }; let blocks_with_ud = vec![ @@ -530,7 +529,7 @@ mod tests { let idty = GvaIdtyDbV1 { is_member: true, joins: svec![BlockNumber(26), BlockNumber(51)], - leaves: BTreeSet::from_iter([BlockNumber(32)].iter().copied()), + leaves: [BlockNumber(32)].iter().copied().collect(), first_ud: Some(BlockNumber(29)), }; diff --git a/rust-libs/modules/gva/src/anti_spam.rs b/rust-libs/modules/gva/src/anti_spam.rs index 925a26d6f..82cd3d87d 100644 --- a/rust-libs/modules/gva/src/anti_spam.rs +++ b/rust-libs/modules/gva/src/anti_spam.rs @@ -18,7 +18,6 @@ use async_mutex::Mutex; use duniter_dbs::kv_typed::prelude::Arc; use std::{ collections::{HashMap, HashSet}, - iter::FromIterator, net::IpAddr, time::Duration, time::Instant, @@ -49,7 +48,7 @@ impl From<&GvaConf> for AntiSpam { ban: HashMap::with_capacity(10), ips_time: HashMap::with_capacity(10), })), - whitelist: HashSet::from_iter(conf.get_whitelist().iter().copied()), + whitelist: conf.get_whitelist().iter().copied().collect(), } } } diff --git a/rust-libs/tools/kv_typed/src/as_bytes.rs b/rust-libs/tools/kv_typed/src/as_bytes.rs index 7158c00e5..c71f6446f 100644 --- a/rust-libs/tools/kv_typed/src/as_bytes.rs +++ b/rust-libs/tools/kv_typed/src/as_bytes.rs @@ -47,7 +47,7 @@ where { fn as_bytes<D, F: FnMut(&[u8]) -> D>(&self, mut f: F) -> D { use zerocopy::AsBytes as _; - f((&SmallVec::<[T; 32]>::from_iter(self.iter().copied())[..]).as_bytes()) + f((&self.iter().copied().collect::<SmallVec<[T; 32]>>()[..]).as_bytes()) } } @@ -57,7 +57,7 @@ where { fn as_bytes<D, F: FnMut(&[u8]) -> D>(&self, mut f: F) -> D { use zerocopy::AsBytes as _; - f((&SmallVec::<[T; 32]>::from_iter(self.iter().copied())[..]).as_bytes()) + f((&self.iter().copied().collect::<SmallVec<[T; 32]>>()[..]).as_bytes()) } } diff --git a/rust-libs/tools/kv_typed/src/from_bytes.rs b/rust-libs/tools/kv_typed/src/from_bytes.rs index 61c0c02d5..8e867e75e 100644 --- a/rust-libs/tools/kv_typed/src/from_bytes.rs +++ b/rust-libs/tools/kv_typed/src/from_bytes.rs @@ -100,7 +100,7 @@ where let layout_verified = zerocopy::LayoutVerified::<_, [T]>::new_slice(bytes) .ok_or(LayoutVerifiedErr(stringify!(BTreeSet<T>)))?; let slice = layout_verified.into_slice(); - Ok(BTreeSet::from_iter(slice.iter().copied())) + Ok(slice.iter().copied().collect()) } } @@ -114,7 +114,7 @@ where let layout_verified = zerocopy::LayoutVerified::<_, [T]>::new_slice(bytes) .ok_or(LayoutVerifiedErr(stringify!(HashSet<T>)))?; let slice = layout_verified.into_slice(); - Ok(HashSet::from_iter(slice.iter().copied())) + Ok(slice.iter().copied().collect()) } } diff --git a/rust-libs/tools/kv_typed/src/lib.rs b/rust-libs/tools/kv_typed/src/lib.rs index bf67d5887..ec24810c2 100644 --- a/rust-libs/tools/kv_typed/src/lib.rs +++ b/rust-libs/tools/kv_typed/src/lib.rs @@ -114,7 +114,6 @@ pub(crate) use std::{ convert::TryInto, error::Error, fmt::{Debug, Display}, - iter::FromIterator, marker::PhantomData, ops::{Bound, RangeBounds}, str::FromStr, diff --git a/rust-libs/tools/kv_typed/tests/test_db_schema.rs b/rust-libs/tools/kv_typed/tests/test_db_schema.rs index 3722783da..645989539 100644 --- a/rust-libs/tools/kv_typed/tests/test_db_schema.rs +++ b/rust-libs/tools/kv_typed/tests/test_db_schema.rs @@ -14,6 +14,7 @@ db_schema!( ); #[test] +#[allow(clippy::eq_op)] fn test_macro_db() { assert_eq!(Col1Event::RemoveAll, Col1Event::RemoveAll); @@ -118,9 +119,8 @@ fn test_db<B: Backend>(db: &TestV1Db<B>) -> KvResult<()> { })?; // Test get_ref_slice - use std::iter::FromIterator as _; db.col4_write() - .upsert(4, BTreeSet::from_iter((&[3, 2, 4, 1]).iter().copied()))?; + .upsert(4, (&[3, 2, 4, 1]).iter().copied().collect())?; db.col4().get_ref_slice(&4, |numbers| { assert_eq!(numbers, &[1, 2, 3, 4]); Ok(()) @@ -195,7 +195,7 @@ fn test_db<B: Backend>(db: &TestV1Db<B>) -> KvResult<()> { Ok::<(), KvError>(()) })?; - c4.upsert(4, BTreeSet::from_iter((&[7, 8, 6, 5]).iter().copied())); + c4.upsert(4, (&[7, 8, 6, 5]).iter().copied().collect()); Ok(()) }); tres?; -- GitLab