Skip to content

Commit

Permalink
chore(clippy): use .fold instead of format!
Browse files Browse the repository at this point in the history
Fix clippy warnings to rust 1.73. Refactor code to use a `.fold` to return a
`Vec<String>` instead of use `format!` in a `.map`.
  • Loading branch information
Tommytrg committed Oct 18, 2023
1 parent eefd36e commit 5a7c8b7
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions data_structures/src/superblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,25 @@ impl SuperBlockVotesMempool {
}

fn get_valid_votes_pretty(&self) -> String {
let mut s: String = self
.votes_on_each_superblock
.iter()
.map(|(superblock_hash, votes)| {
let mut s: String = self.votes_on_each_superblock.iter().fold(
String::new(),
|mut acc, (superblock_hash, votes)| {
let pkhs: Vec<String> = votes
.iter()
.map(|vote| vote.secp256k1_signature.public_key.pkh())
.map(|pkh| pkh.to_string())
.collect();

format!(" {}: {} votes: {:?}\n", superblock_hash, pkhs.len(), pkhs)
})
.collect();
acc.push_str(&format!(
" {}: {} votes: {:?}\n",
superblock_hash,
pkhs.len(),
pkhs
));

acc
},
);

// Remove trailing "\n" if `s` is not empty
s.pop();
Expand Down

0 comments on commit 5a7c8b7

Please sign in to comment.