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

*: Apply clippy suggestions #2540

Merged
merged 1 commit into from
Feb 28, 2022
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
7 changes: 1 addition & 6 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,9 @@ where

/// Lists all mesh peers for a certain topic hash.
pub fn mesh_peers(&self, topic_hash: &TopicHash) -> impl Iterator<Item = &PeerId> {
self.mesh
.get(topic_hash)
.into_iter()
.map(|x| x.iter())
.flatten()
self.mesh.get(topic_hash).into_iter().flat_map(|x| x.iter())
}

/// Lists all mesh peers for all topics.
pub fn all_mesh_peers(&self) -> impl Iterator<Item = &PeerId> {
let mut res = BTreeSet::new();
for peers in self.mesh.values() {
Expand Down
3 changes: 1 addition & 2 deletions protocols/identify/src/identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ impl NetworkBehaviour for Identify {
if let Some(entry) = self.discovered_peers.get_mut(peer_id) {
for addr in failed_addresses
.into_iter()
.map(|addresses| addresses.into_iter())
.flatten()
.flat_map(|addresses| addresses.into_iter())
{
entry.remove(addr);
}
Expand Down
5 changes: 2 additions & 3 deletions protocols/relay/src/v1/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,11 @@ impl NetworkBehaviour for Relay {
.get(remote_peer_id)
.into_iter()
.flatten()
.map(
.flat_map(
|IncomingRelayReq::DialingDst {
incoming_relay_req, ..
}| incoming_relay_req.dst_peer().addrs.clone(),
)
.flatten(),
),
)
.collect()
}
Expand Down
6 changes: 2 additions & 4 deletions protocols/relay/src/v1/protocol/outgoing_dst_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ impl upgrade::OutboundUpgrade<NegotiatedSubstream> for OutgoingDstReq {
} = CircuitRelay::decode(msg)?;

match r#type
.map(circuit_relay::Type::from_i32)
.flatten()
.and_then(circuit_relay::Type::from_i32)
.ok_or(OutgoingDstReqError::ParseTypeField)?
{
circuit_relay::Type::Status => {}
Expand All @@ -126,8 +125,7 @@ impl upgrade::OutboundUpgrade<NegotiatedSubstream> for OutgoingDstReq {
}

match code
.map(circuit_relay::Status::from_i32)
.flatten()
.and_then(circuit_relay::Status::from_i32)
.ok_or(OutgoingDstReqError::ParseStatusField)?
{
circuit_relay::Status::Success => {}
Expand Down
6 changes: 2 additions & 4 deletions protocols/relay/src/v1/protocol/outgoing_relay_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,15 @@ impl upgrade::OutboundUpgrade<NegotiatedSubstream> for OutgoingRelayReq {
} = CircuitRelay::decode(msg)?;

match r#type
.map(circuit_relay::Type::from_i32)
.flatten()
.and_then(circuit_relay::Type::from_i32)
.ok_or(OutgoingRelayReqError::ParseTypeField)?
{
circuit_relay::Type::Status => {}
s => return Err(OutgoingRelayReqError::ExpectedStatusType(s)),
}

match code
.map(circuit_relay::Status::from_i32)
.flatten()
.and_then(circuit_relay::Status::from_i32)
.ok_or(OutgoingRelayReqError::ParseStatusField)?
{
circuit_relay::Status::Success => {}
Expand Down
3 changes: 1 addition & 2 deletions protocols/relay/src/v2/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,7 @@ impl NetworkBehaviour for Relay {
} else if let Some(dst_conn) = self
.reservations
.get(&inbound_circuit_req.dst())
.map(|cs| cs.iter().next())
.flatten()
.and_then(|cs| cs.iter().next())
{
// Accept circuit request if reservation present.
let circuit_id = self.circuits.insert(Circuit {
Expand Down
3 changes: 1 addition & 2 deletions swarm/src/handler/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,7 @@ where
self.upgrades
.iter()
.enumerate()
.map(|(i, (_, h))| iter::repeat(i).zip(h.protocol_info()))
.flatten()
.flat_map(|(i, (_, h))| iter::repeat(i).zip(h.protocol_info()))
.map(|(i, h)| IndexedProtoName(i, h))
.collect::<Vec<_>>()
.into_iter()
Expand Down
8 changes: 4 additions & 4 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,16 +1192,16 @@ pub struct SwarmPollParameters<'a> {
}

impl<'a> PollParameters for SwarmPollParameters<'a> {
type SupportedProtocolsIter = std::vec::IntoIter<Vec<u8>>;
type ListenedAddressesIter = std::vec::IntoIter<Multiaddr>;
type SupportedProtocolsIter = std::iter::Cloned<std::slice::Iter<'a, std::vec::Vec<u8>>>;
type ListenedAddressesIter = std::iter::Cloned<std::slice::Iter<'a, Multiaddr>>;
type ExternalAddressesIter = AddressIntoIter;

fn supported_protocols(&self) -> Self::SupportedProtocolsIter {
self.supported_protocols.to_vec().into_iter()
self.supported_protocols.iter().cloned()
}

fn listened_addresses(&self) -> Self::ListenedAddressesIter {
self.listened_addrs.to_vec().into_iter()
self.listened_addrs.iter().cloned()
}

fn external_addresses(&self) -> Self::ExternalAddressesIter {
Expand Down
52 changes: 23 additions & 29 deletions transports/wasm-ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,39 +311,33 @@ impl Stream for Listen {
return Poll::Ready(None);
};

for addr in event
.new_addrs()
.into_iter()
.flat_map(|e| e.to_vec().into_iter())
{
let addr = js_value_to_addr(&addr)?;
self.pending_events
.push_back(ListenerEvent::NewAddress(addr));
if let Some(addrs) = event.new_addrs() {
for addr in addrs.into_iter() {
let addr = js_value_to_addr(&addr)?;
self.pending_events
.push_back(ListenerEvent::NewAddress(addr));
}
}

for upgrade in event
.new_connections()
.into_iter()
.flat_map(|e| e.to_vec().into_iter())
{
let upgrade: ffi::ConnectionEvent = upgrade.into();
self.pending_events.push_back(ListenerEvent::Upgrade {
local_addr: upgrade.local_addr().parse()?,
remote_addr: upgrade.observed_addr().parse()?,
upgrade: futures::future::ok(Connection::new(upgrade.connection())),
});
if let Some(upgrades) = event.new_connections() {
for upgrade in upgrades.into_iter().cloned() {
let upgrade: ffi::ConnectionEvent = upgrade.into();
self.pending_events.push_back(ListenerEvent::Upgrade {
local_addr: upgrade.local_addr().parse()?,
remote_addr: upgrade.observed_addr().parse()?,
upgrade: futures::future::ok(Connection::new(upgrade.connection())),
});
}
}

for addr in event
.expired_addrs()
.into_iter()
.flat_map(|e| e.to_vec().into_iter())
{
match js_value_to_addr(&addr) {
Ok(addr) => self
.pending_events
.push_back(ListenerEvent::NewAddress(addr)),
Err(err) => self.pending_events.push_back(ListenerEvent::Error(err)),
if let Some(addrs) = event.expired_addrs() {
for addr in addrs.into_iter() {
match js_value_to_addr(&addr) {
Ok(addr) => self
.pending_events
.push_back(ListenerEvent::NewAddress(addr)),
Err(err) => self.pending_events.push_back(ListenerEvent::Error(err)),
}
}
}
}
Expand Down