Skip to content

Commit 22fbce3

Browse files
authored
*: Fix clippy warnings (#2615)
1 parent 0c1ac78 commit 22fbce3

File tree

16 files changed

+67
-39
lines changed

16 files changed

+67
-39
lines changed

core/src/identity/rsa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl DerDecodable<'_> for Asn1SubjectPublicKey {
263263
)));
264264
}
265265

266-
let pk_der: Vec<u8> = object.value().into_iter().skip(1).cloned().collect();
266+
let pk_der: Vec<u8> = object.value().iter().skip(1).cloned().collect();
267267
// We don't parse pk_der further as an ASN.1 RsaPublicKey, since
268268
// we only need the DER encoding for `verify`.
269269
Ok(Self(PublicKey(pk_der)))

core/src/peer_id.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl PeerId {
9494
/// In case the given [`Multiaddr`] ends with `/p2p/<peer-id>`, this function
9595
/// will return the encapsulated [`PeerId`], otherwise it will return `None`.
9696
pub fn try_from_multiaddr(address: &Multiaddr) -> Option<PeerId> {
97-
address.iter().last().map_or(None, |p| match p {
97+
address.iter().last().and_then(|p| match p {
9898
Protocol::P2p(hash) => PeerId::from_multihash(hash).ok(),
9999
_ => None,
100100
})

core/src/peer_record.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl PeerRecord {
8989
};
9090

9191
let envelope = SignedEnvelope::new(
92-
&key,
92+
key,
9393
String::from(DOMAIN_SEP),
9494
PAYLOAD_TYPE.as_bytes().to_vec(),
9595
payload,

core/src/transport/memory.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ impl<T> Sink<T> for Chan<T> {
358358
}
359359
}
360360

361-
impl<T: AsRef<[u8]>> Into<RwStreamSink<Chan<T>>> for Chan<T> {
362-
fn into(self) -> RwStreamSink<Chan<T>> {
363-
RwStreamSink::new(self)
361+
impl<T: AsRef<[u8]>> From<Chan<T>> for RwStreamSink<Chan<T>> {
362+
fn from(channel: Chan<T>) -> RwStreamSink<Chan<T>> {
363+
RwStreamSink::new(channel)
364364
}
365365
}
366366

muxers/mplex/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use crate::codec::MAX_FRAME_SIZE;
2222
use std::cmp;
2323

24-
pub(crate) const DEFAULT_MPLEX_PROTOCOL_NAME: &'static [u8] = b"/mplex/6.7.0";
24+
pub(crate) const DEFAULT_MPLEX_PROTOCOL_NAME: &[u8] = b"/mplex/6.7.0";
2525

2626
/// Configuration for the multiplexer.
2727
#[derive(Debug, Clone)]

muxers/mplex/src/io.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -810,10 +810,10 @@ where
810810

811811
/// Checks whether a substream is open for reading.
812812
fn can_read(&self, id: &LocalStreamId) -> bool {
813-
match self.substreams.get(id) {
814-
Some(SubstreamState::Open { .. }) | Some(SubstreamState::SendClosed { .. }) => true,
815-
_ => false,
816-
}
813+
matches!(
814+
self.substreams.get(id),
815+
Some(SubstreamState::Open { .. }) | Some(SubstreamState::SendClosed { .. })
816+
)
817817
}
818818

819819
/// Sends pending frames, without flushing.

muxers/yamux/src/lib.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,19 @@ impl YamuxConfig {
252252
/// Creates a new `YamuxConfig` in client mode, regardless of whether
253253
/// it will be used for an inbound or outbound upgrade.
254254
pub fn client() -> Self {
255-
let mut cfg = Self::default();
256-
cfg.mode = Some(yamux::Mode::Client);
257-
cfg
255+
Self {
256+
mode: Some(yamux::Mode::Client),
257+
..Default::default()
258+
}
258259
}
259260

260261
/// Creates a new `YamuxConfig` in server mode, regardless of whether
261262
/// it will be used for an inbound or outbound upgrade.
262263
pub fn server() -> Self {
263-
let mut cfg = Self::default();
264-
cfg.mode = Some(yamux::Mode::Server);
265-
cfg
264+
Self {
265+
mode: Some(yamux::Mode::Server),
266+
..Default::default()
267+
}
266268
}
267269

268270
/// Sets the size (in bytes) of the receive window per substream.

swarm/src/behaviour/either.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ where
227227
) -> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ConnectionHandler>> {
228228
let event = match self {
229229
Either::Left(behaviour) => futures::ready!(behaviour.poll(cx, params))
230-
.map_out(|e| Either::Left(e))
231-
.map_handler_and_in(|h| IntoEitherHandler::Left(h), |e| Either::Left(e)),
230+
.map_out(Either::Left)
231+
.map_handler_and_in(IntoEitherHandler::Left, Either::Left),
232232
Either::Right(behaviour) => futures::ready!(behaviour.poll(cx, params))
233-
.map_out(|e| Either::Right(e))
234-
.map_handler_and_in(|h| IntoEitherHandler::Right(h), |e| Either::Right(e)),
233+
.map_out(Either::Right)
234+
.map_handler_and_in(IntoEitherHandler::Right, Either::Right),
235235
};
236236

237237
Poll::Ready(event)

swarm/src/connection/pool/concurrent_dial.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ where
6060
let mut pending_dials = pending_dials.into_iter();
6161

6262
let dials = FuturesUnordered::new();
63-
while let Some(dial) = pending_dials.next() {
63+
for dial in pending_dials.by_ref() {
6464
dials.push(dial);
6565
if dials.len() == concurrency_factor.get() as usize {
6666
break;
@@ -95,7 +95,7 @@ where
9595
loop {
9696
match ready!(self.dials.poll_next_unpin(cx)) {
9797
Some((addr, Ok(output))) => {
98-
let errors = std::mem::replace(&mut self.errors, vec![]);
98+
let errors = std::mem::take(&mut self.errors);
9999
return Poll::Ready(Ok((addr, output, errors)));
100100
}
101101
Some((addr, Err(e))) => {
@@ -105,7 +105,7 @@ where
105105
}
106106
}
107107
None => {
108-
return Poll::Ready(Err(std::mem::replace(&mut self.errors, vec![])));
108+
return Poll::Ready(Err(std::mem::take(&mut self.errors)));
109109
}
110110
}
111111
}

swarm/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ where
514514
};
515515
match dial {
516516
Ok(fut) => fut
517-
.map(|r| (address, r.map_err(|e| TransportError::Other(e))))
517+
.map(|r| (address, r.map_err(TransportError::Other)))
518518
.boxed(),
519519
Err(err) => futures::future::ready((address, Err(err))).boxed(),
520520
}
@@ -538,7 +538,7 @@ where
538538
Err((connection_limit, handler)) => {
539539
let error = DialError::ConnectionLimit(connection_limit);
540540
self.behaviour.inject_dial_failure(None, handler, &error);
541-
return Err(error);
541+
Err(error)
542542
}
543543
}
544544
}
@@ -800,7 +800,7 @@ where
800800
.expect("n + 1 is always non-zero; qed");
801801
let non_banned_established = other_established_connection_ids
802802
.into_iter()
803-
.filter(|conn_id| !this.banned_peer_connections.contains(&conn_id))
803+
.filter(|conn_id| !this.banned_peer_connections.contains(conn_id))
804804
.count();
805805

806806
log::debug!(
@@ -896,7 +896,7 @@ where
896896
if conn_was_reported {
897897
let remaining_non_banned = remaining_established_connection_ids
898898
.into_iter()
899-
.filter(|conn_id| !this.banned_peer_connections.contains(&conn_id))
899+
.filter(|conn_id| !this.banned_peer_connections.contains(conn_id))
900900
.count();
901901
this.behaviour.inject_connection_closed(
902902
&peer_id,

0 commit comments

Comments
 (0)