Skip to content

Commit

Permalink
apply some clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Istvan Ruzman committed Jul 4, 2024
1 parent a0cddff commit 2642eea
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
13 changes: 5 additions & 8 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async fn query<T: Store>(
}
}
if let Some(asn_dns_zone) = &cfg.asn_dns_zone {
for asn in route.attrs.as_path.into_iter().flat_map(|x| x) {
for asn in route.attrs.as_path.into_iter().flatten() {
if have_asn.insert(asn) {
let resolver = resolver.clone();
let asn_dns_zone = asn_dns_zone.clone();
Expand All @@ -286,10 +286,7 @@ async fn query<T: Store>(
.next()
.and_then(|data| std::str::from_utf8(data).ok())
.and_then(|s| {
s.split(" | ")
.skip(4)
.next()
.map(|name| name.to_string())
s.split(" | ").nth(4).map(|name| name.to_string())
})
})
})
Expand All @@ -298,7 +295,7 @@ async fn query<T: Store>(
}
}
}
for community in route.attrs.communities.into_iter().flat_map(|x| x) {
for community in route.attrs.communities.into_iter().flatten() {
if have_community.insert(community) {
let community_str = format!("{}:{}", community.0, community.1);
if let Some(lookup) = community_lists.regular.lookup(&community_str) {
Expand All @@ -311,7 +308,7 @@ async fn query<T: Store>(
}
}
}
for large_community in route.attrs.large_communities.into_iter().flat_map(|x| x) {
for large_community in route.attrs.large_communities.into_iter().flatten() {
if have_large_community.insert(large_community) {
let large_community_str = format!(
"{}:{}:{}",
Expand All @@ -330,7 +327,7 @@ async fn query<T: Store>(

futures
})
.filter_map(|x| futures_util::future::ready(x))
.filter_map(futures_util::future::ready)
.map(|result| {
let json = serde_json::to_string(&result).unwrap();
Ok::<_, Infallible>(format!("{}\n", json))
Expand Down
2 changes: 1 addition & 1 deletion src/bgp_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub async fn run_peer(
.or(open_message.caps.iter().find_map(|x| {
if let BgpCapability::CapFQDN(hostname, domainname) = x {
let mut name = hostname.to_string();
if domainname != "" {
if domainname.is_empty() {
name = format!("{}.{}", name, domainname);
}
Some(name)
Expand Down
8 changes: 4 additions & 4 deletions src/bgpdumper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl BgpDumper {
}
pub async fn start_active(&mut self) -> Result<BgpOpenMessage, BgpError> {
let mut bom = self.params.open_message();
let mut buf = [255 as u8; 4096];
let mut buf = [255u8; 4096];
let messagelen = match bom.encode_to(&self.params, &mut buf[19..]) {
Err(e) => {
return Err(e);
Expand All @@ -58,7 +58,7 @@ impl BgpDumper {
bom.decode_from(&self.params, &buf[..])?;
debug!("{:?}", bom);
self.params.hold_time = bom.hold_time;
self.params.caps = bom.caps.clone();
self.params.caps.clone_from(&bom.caps);
self.params.check_caps();
Ok(bom)
}
Expand All @@ -67,8 +67,8 @@ impl BgpDumper {
let slp = std::time::Duration::new((self.params.hold_time / 3) as u64, 0);
let write = self.write.clone();
tokio::task::spawn(async move {
let mut buf = [255 as u8; 19];
buf[0..16].clone_from_slice(&[255 as u8; 16]);
let mut buf = [255u8; 19];
buf[0..16].clone_from_slice(&[255u8; 16]);
buf[16] = 0;
buf[17] = 19;
buf[18] = 4; //keepalive
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ async fn main() -> anyhow::Result<()> {

futures.extend(
cfg.collectors
.into_iter()
.map(|(_, collector)| match collector {
.into_values()
.map(|collector| match collector {
CollectorConfig::Bmp(cfg) => {
tokio::task::spawn(bmp_collector::run(cfg, store.clone(), shutdown_rx.clone()))
}
Expand Down
4 changes: 2 additions & 2 deletions src/store_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,15 @@ impl Store for InMemoryStore {
let clients = clients.clone();
let sessions = sessions.clone();
async move {
let client = match clients.lock().unwrap().get(&table.client_addr()) {
let client = match clients.lock().unwrap().get(table.client_addr()) {
Some(v) => v.clone(),
None => {
warn!("client is not connected");
return None;
}
};
let session = table.session_id().and_then(|session_id| {
sessions.lock().unwrap().get(&session_id).cloned()
sessions.lock().unwrap().get(session_id).cloned()
});

Some(QueryResult {
Expand Down
8 changes: 4 additions & 4 deletions src/table_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ impl NodeExt for Node<IpNet, Vec<(PathId, Arc<CompressedRouteAttrs>)>> {
dyn Iterator<Item = (IpNet, &Vec<(PathId, Arc<CompressedRouteAttrs>)>)> + Send + '_,
> = match net_query {
None => Box::new(self.iter()),
Some(NetQuery::Exact(net)) => Box::new(self.exact(&net).map(|x| (*net, x)).into_iter()),
Some(NetQuery::MostSpecific(net)) => Box::new(self.longest_match(&net).into_iter()),
Some(NetQuery::Contains(net)) => Box::new(self.matches(&net)),
Some(NetQuery::OrLonger(net)) => Box::new(self.or_longer(&net)),
Some(NetQuery::Exact(net)) => Box::new(self.exact(net).map(|x| (*net, x)).into_iter()),
Some(NetQuery::MostSpecific(net)) => Box::new(self.longest_match(net).into_iter()),
Some(NetQuery::Contains(net)) => Box::new(self.matches(net)),
Some(NetQuery::OrLonger(net)) => Box::new(self.or_longer(net)),
};
Box::new(iter.flat_map(move |(net, routes)| {
routes
Expand Down

0 comments on commit 2642eea

Please sign in to comment.