Skip to content

Commit 2642eea

Browse files
author
Istvan Ruzman
committed
apply some clippy suggestions
1 parent a0cddff commit 2642eea

File tree

6 files changed

+18
-21
lines changed

6 files changed

+18
-21
lines changed

src/api.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ async fn query<T: Store>(
271271
}
272272
}
273273
if let Some(asn_dns_zone) = &cfg.asn_dns_zone {
274-
for asn in route.attrs.as_path.into_iter().flat_map(|x| x) {
274+
for asn in route.attrs.as_path.into_iter().flatten() {
275275
if have_asn.insert(asn) {
276276
let resolver = resolver.clone();
277277
let asn_dns_zone = asn_dns_zone.clone();
@@ -286,10 +286,7 @@ async fn query<T: Store>(
286286
.next()
287287
.and_then(|data| std::str::from_utf8(data).ok())
288288
.and_then(|s| {
289-
s.split(" | ")
290-
.skip(4)
291-
.next()
292-
.map(|name| name.to_string())
289+
s.split(" | ").nth(4).map(|name| name.to_string())
293290
})
294291
})
295292
})
@@ -298,7 +295,7 @@ async fn query<T: Store>(
298295
}
299296
}
300297
}
301-
for community in route.attrs.communities.into_iter().flat_map(|x| x) {
298+
for community in route.attrs.communities.into_iter().flatten() {
302299
if have_community.insert(community) {
303300
let community_str = format!("{}:{}", community.0, community.1);
304301
if let Some(lookup) = community_lists.regular.lookup(&community_str) {
@@ -311,7 +308,7 @@ async fn query<T: Store>(
311308
}
312309
}
313310
}
314-
for large_community in route.attrs.large_communities.into_iter().flat_map(|x| x) {
311+
for large_community in route.attrs.large_communities.into_iter().flatten() {
315312
if have_large_community.insert(large_community) {
316313
let large_community_str = format!(
317314
"{}:{}:{}",
@@ -330,7 +327,7 @@ async fn query<T: Store>(
330327

331328
futures
332329
})
333-
.filter_map(|x| futures_util::future::ready(x))
330+
.filter_map(futures_util::future::ready)
334331
.map(|result| {
335332
let json = serde_json::to_string(&result).unwrap();
336333
Ok::<_, Infallible>(format!("{}\n", json))

src/bgp_collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub async fn run_peer(
4848
.or(open_message.caps.iter().find_map(|x| {
4949
if let BgpCapability::CapFQDN(hostname, domainname) = x {
5050
let mut name = hostname.to_string();
51-
if domainname != "" {
51+
if domainname.is_empty() {
5252
name = format!("{}.{}", name, domainname);
5353
}
5454
Some(name)

src/bgpdumper.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl BgpDumper {
4040
}
4141
pub async fn start_active(&mut self) -> Result<BgpOpenMessage, BgpError> {
4242
let mut bom = self.params.open_message();
43-
let mut buf = [255 as u8; 4096];
43+
let mut buf = [255u8; 4096];
4444
let messagelen = match bom.encode_to(&self.params, &mut buf[19..]) {
4545
Err(e) => {
4646
return Err(e);
@@ -58,7 +58,7 @@ impl BgpDumper {
5858
bom.decode_from(&self.params, &buf[..])?;
5959
debug!("{:?}", bom);
6060
self.params.hold_time = bom.hold_time;
61-
self.params.caps = bom.caps.clone();
61+
self.params.caps.clone_from(&bom.caps);
6262
self.params.check_caps();
6363
Ok(bom)
6464
}
@@ -67,8 +67,8 @@ impl BgpDumper {
6767
let slp = std::time::Duration::new((self.params.hold_time / 3) as u64, 0);
6868
let write = self.write.clone();
6969
tokio::task::spawn(async move {
70-
let mut buf = [255 as u8; 19];
71-
buf[0..16].clone_from_slice(&[255 as u8; 16]);
70+
let mut buf = [255u8; 19];
71+
buf[0..16].clone_from_slice(&[255u8; 16]);
7272
buf[16] = 0;
7373
buf[17] = 19;
7474
buf[18] = 4; //keepalive

src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ async fn main() -> anyhow::Result<()> {
4444

4545
futures.extend(
4646
cfg.collectors
47-
.into_iter()
48-
.map(|(_, collector)| match collector {
47+
.into_values()
48+
.map(|collector| match collector {
4949
CollectorConfig::Bmp(cfg) => {
5050
tokio::task::spawn(bmp_collector::run(cfg, store.clone(), shutdown_rx.clone()))
5151
}

src/store_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,15 @@ impl Store for InMemoryStore {
191191
let clients = clients.clone();
192192
let sessions = sessions.clone();
193193
async move {
194-
let client = match clients.lock().unwrap().get(&table.client_addr()) {
194+
let client = match clients.lock().unwrap().get(table.client_addr()) {
195195
Some(v) => v.clone(),
196196
None => {
197197
warn!("client is not connected");
198198
return None;
199199
}
200200
};
201201
let session = table.session_id().and_then(|session_id| {
202-
sessions.lock().unwrap().get(&session_id).cloned()
202+
sessions.lock().unwrap().get(session_id).cloned()
203203
});
204204

205205
Some(QueryResult {

src/table_impl.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ impl NodeExt for Node<IpNet, Vec<(PathId, Arc<CompressedRouteAttrs>)>> {
2727
dyn Iterator<Item = (IpNet, &Vec<(PathId, Arc<CompressedRouteAttrs>)>)> + Send + '_,
2828
> = match net_query {
2929
None => Box::new(self.iter()),
30-
Some(NetQuery::Exact(net)) => Box::new(self.exact(&net).map(|x| (*net, x)).into_iter()),
31-
Some(NetQuery::MostSpecific(net)) => Box::new(self.longest_match(&net).into_iter()),
32-
Some(NetQuery::Contains(net)) => Box::new(self.matches(&net)),
33-
Some(NetQuery::OrLonger(net)) => Box::new(self.or_longer(&net)),
30+
Some(NetQuery::Exact(net)) => Box::new(self.exact(net).map(|x| (*net, x)).into_iter()),
31+
Some(NetQuery::MostSpecific(net)) => Box::new(self.longest_match(net).into_iter()),
32+
Some(NetQuery::Contains(net)) => Box::new(self.matches(net)),
33+
Some(NetQuery::OrLonger(net)) => Box::new(self.or_longer(net)),
3434
};
3535
Box::new(iter.flat_map(move |(net, routes)| {
3636
routes

0 commit comments

Comments
 (0)