Skip to content

Commit 3d3666e

Browse files
*: Enforce no clippy warnings for examples (#2826)
1 parent 8931860 commit 3d3666e

File tree

7 files changed

+17
-21
lines changed

7 files changed

+17
-21
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[alias]
22
# Temporary solution to have clippy config in a single place until https://github.com/rust-lang/rust-clippy/blob/master/doc/roadmap-2021.md#lintstoml-configuration is shipped.
3-
custom-clippy = "clippy --all-features -- -A clippy::type_complexity -A clippy::pedantic -D warnings"
3+
custom-clippy = "clippy --all-features --all-targets -- -A clippy::type_complexity -A clippy::pedantic -D warnings"

examples/chat-tokio.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
9191
mdns: Mdns,
9292
}
9393

94+
#[allow(clippy::large_enum_variant)]
9495
enum MyBehaviourEvent {
9596
Floodsub(FloodsubEvent),
9697
Mdns(MdnsEvent),
@@ -112,7 +113,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
112113
let mut swarm = {
113114
let mdns = Mdns::new(Default::default()).await?;
114115
let mut behaviour = MyBehaviour {
115-
floodsub: Floodsub::new(peer_id.clone()),
116+
floodsub: Floodsub::new(peer_id),
116117
mdns,
117118
};
118119

@@ -152,14 +153,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
152153
SwarmEvent::NewListenAddr { address, .. } => {
153154
println!("Listening on {:?}", address);
154155
}
155-
SwarmEvent::Behaviour(MyBehaviourEvent::Floodsub(event)) => {
156-
if let FloodsubEvent::Message(message) = event {
157-
println!(
156+
SwarmEvent::Behaviour(MyBehaviourEvent::Floodsub(FloodsubEvent::Message(message))) => {
157+
println!(
158158
"Received: '{:?}' from {:?}",
159159
String::from_utf8_lossy(&message.data),
160160
message.source
161161
);
162-
}
163162
}
164163
SwarmEvent::Behaviour(MyBehaviourEvent::Mdns(event)) => {
165164
match event {

examples/chat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
9292
ignored_member: bool,
9393
}
9494

95+
#[allow(clippy::large_enum_variant)]
9596
#[derive(Debug)]
9697
enum OutEvent {
9798
Floodsub(FloodsubEvent),

examples/file-sharing.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ mod network {
221221
};
222222
use libp2p::swarm::{ConnectionHandlerUpgrErr, SwarmBuilder, SwarmEvent};
223223
use libp2p::{NetworkBehaviour, Swarm};
224-
use std::collections::{HashMap, HashSet};
224+
use std::collections::{hash_map, HashMap, HashSet};
225225
use std::iter;
226226

227227
/// Creates the network components, namely:
@@ -359,10 +359,7 @@ mod network {
359359
channel: ResponseChannel<FileResponse>,
360360
) {
361361
self.sender
362-
.send(Command::RespondFile {
363-
file: file,
364-
channel,
365-
})
362+
.send(Command::RespondFile { file, channel })
366363
.await
367364
.expect("Command receiver not to be dropped.");
368365
}
@@ -527,9 +524,7 @@ mod network {
527524
peer_addr,
528525
sender,
529526
} => {
530-
if self.pending_dial.contains_key(&peer_id) {
531-
todo!("Already dialing peer.");
532-
} else {
527+
if let hash_map::Entry::Vacant(e) = self.pending_dial.entry(peer_id) {
533528
self.swarm
534529
.behaviour_mut()
535530
.kademlia
@@ -539,12 +534,14 @@ mod network {
539534
.dial(peer_addr.with(Protocol::P2p(peer_id.into())))
540535
{
541536
Ok(()) => {
542-
self.pending_dial.insert(peer_id, sender);
537+
e.insert(sender);
543538
}
544539
Err(e) => {
545540
let _ = sender.send(Err(Box::new(e)));
546541
}
547542
}
543+
} else {
544+
todo!("Already dialing peer.");
548545
}
549546
}
550547
Command::StartProviding { file_name, sender } => {

examples/gossipsub-chat.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
101101

102102
// add an explicit peer if one was provided
103103
if let Some(explicit) = std::env::args().nth(2) {
104-
let explicit = explicit.clone();
105104
match explicit.parse() {
106105
Ok(id) => gossipsub.add_explicit_peer(&id),
107106
Err(err) => println!("Failed to parse explicit peer id: {:?}", err),

examples/ipfs-kad.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use libp2p::{
3434
};
3535
use std::{env, error::Error, str::FromStr, time::Duration};
3636

37-
const BOOTNODES: [&'static str; 4] = [
37+
const BOOTNODES: [&str; 4] = [
3838
"QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
3939
"QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
4040
"QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",

examples/ipfs-private.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn get_ipfs_path() -> Box<Path> {
9292
}
9393

9494
/// Read the pre shared key file from the given ipfs directory
95-
fn get_psk(path: Box<Path>) -> std::io::Result<Option<String>> {
95+
fn get_psk(path: &Path) -> std::io::Result<Option<String>> {
9696
let swarm_key_file = path.join("swarm.key");
9797
match fs::read_to_string(swarm_key_file) {
9898
Ok(text) => Ok(Some(text)),
@@ -136,17 +136,17 @@ fn parse_legacy_multiaddr(text: &str) -> Result<Multiaddr, Box<dyn Error>> {
136136
async fn main() -> Result<(), Box<dyn Error>> {
137137
env_logger::init();
138138

139-
let ipfs_path: Box<Path> = get_ipfs_path();
139+
let ipfs_path = get_ipfs_path();
140140
println!("using IPFS_PATH {:?}", ipfs_path);
141-
let psk: Option<PreSharedKey> = get_psk(ipfs_path)?
141+
let psk: Option<PreSharedKey> = get_psk(&ipfs_path)?
142142
.map(|text| PreSharedKey::from_str(&text))
143143
.transpose()?;
144144

145145
// Create a random PeerId
146146
let local_key = identity::Keypair::generate_ed25519();
147147
let local_peer_id = PeerId::from(local_key.public());
148148
println!("using random peer id: {:?}", local_peer_id);
149-
for psk in psk {
149+
if let Some(psk) = psk {
150150
println!("using swarm key with fingerprint: {}", psk.fingerprint());
151151
}
152152

0 commit comments

Comments
 (0)