mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-06 12:39:51 +00:00
disallow some methods from itertools
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
disallowed-methods = [
|
||||
{ path = "itertools::Itertools::map_into", reason = "Blocks underlying iterator optimizations. Use the native `.map(Into::into)` instead." },
|
||||
{ path = "itertools::Itertools::map_ok", reason = "Blocks underlying iterator optimizations. Use the native `.map(|r| r.map(f))` instead." },
|
||||
{ path = "itertools::Itertools::filter_ok", reason = "Blocks underlying iterator optimizations. Use a native approach, e.g., `.filter(|r| r.as_ref().map_or(true, condition))`." },
|
||||
{ path = "itertools::Itertools::filter_map_ok", reason = "Blocks underlying iterator optimizations. Use native `.map()` and `.flatten()`, or extract logic into a standard `.filter_map()`." },
|
||||
|
||||
{ path = "itertools::Itertools::collect_vec", reason = "Non-standard idiom. Directly use the standard library's `.collect::<Vec<_>>()`." },
|
||||
{ path = "itertools::Itertools::try_collect", reason = "Non-standard idiom. Standard `collect()` already supports Result/Option inversion; use `.collect::<Result<_, _>>()`." },
|
||||
{ path = "itertools::Itertools::set_from", reason = "Non-standard idiom. Directly use the `.extend()` method provided by the standard library's `Extend` trait." },
|
||||
{ path = "itertools::Itertools::concat", reason = "Non-standard idiom. Use native `.flatten().collect()` or a slice's `.concat()` instead." }
|
||||
]
|
||||
@@ -38,7 +38,6 @@ use crate::{
|
||||
};
|
||||
use crossbeam::atomic::AtomicCell;
|
||||
use hmac::{Hmac, Mac};
|
||||
use itertools::Itertools;
|
||||
use parking_lot::RwLock;
|
||||
use sha2::Sha256;
|
||||
use socket2::Protocol;
|
||||
@@ -710,7 +709,7 @@ impl DnsGlobalCtxExt for GlobalCtx {
|
||||
zones: self
|
||||
.dns_iter_zones()
|
||||
.filter(|z| z.policy.export.as_ref().is_some_and(|f| !f.disabled)) // TODO: check policies of parent zones
|
||||
.map_into()
|
||||
.map(Into::into)
|
||||
.collect(),
|
||||
fqdn: self.config.get_dns().get_fqdn().to_string(),
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ use crate::{
|
||||
use anyhow::Context;
|
||||
use dashmap::DashSet;
|
||||
use hickory_resolver::proto::rr::rdata::SRV;
|
||||
use itertools::Itertools;
|
||||
use rand::{seq::SliceRandom, Rng as _};
|
||||
use strum::VariantArray;
|
||||
|
||||
@@ -117,7 +116,7 @@ impl DnsTunnelConnector {
|
||||
let srv_domains = IpScheme::VARIANTS
|
||||
.iter()
|
||||
.map(|s| (s, format!("_easytier._{}.{}", s, domain_name)))
|
||||
.collect_vec();
|
||||
.collect::<Vec<_>>();
|
||||
tracing::info!("build srv_domains: {:?}", srv_domains);
|
||||
let responses = Arc::new(DashSet::new());
|
||||
let srv_lookup_tasks = srv_domains
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::proto::dns::DnsNodeMgrRpc;
|
||||
use crate::proto::dns::{DnsSnapshot, HeartbeatRequest, HeartbeatResponse};
|
||||
use crate::proto::rpc_types;
|
||||
use crate::proto::rpc_types::controller::BaseController;
|
||||
use crate::utils::{DeterministicDigest, MapTryInto};
|
||||
use crate::utils::DeterministicDigest;
|
||||
use anyhow::Error;
|
||||
use hickory_server::authority::Catalog;
|
||||
use itertools::Itertools;
|
||||
@@ -30,8 +30,16 @@ impl TryFrom<&DnsSnapshot> for DnsNodeInfo {
|
||||
Ok(Self {
|
||||
digest: value.digest(),
|
||||
zones: (&value.zones).try_into()?,
|
||||
addresses: value.addresses.iter().map_try_into().try_collect()?,
|
||||
listeners: value.listeners.iter().map_try_into().try_collect()?,
|
||||
addresses: value
|
||||
.addresses
|
||||
.iter()
|
||||
.map(TryInto::try_into)
|
||||
.collect::<Result<_, _>>()?,
|
||||
listeners: value
|
||||
.listeners
|
||||
.iter()
|
||||
.map(TryInto::try_into)
|
||||
.collect::<Result<_, _>>()?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ use crate::proto::rpc_types;
|
||||
use crate::proto::rpc_types::controller::BaseController;
|
||||
use crate::utils::DeterministicDigest;
|
||||
use anyhow::Context;
|
||||
use itertools::Itertools;
|
||||
use moka::future::Cache;
|
||||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
@@ -53,7 +52,7 @@ impl DnsPeerMgrInner {
|
||||
|
||||
let zones = global_ctx
|
||||
.dns_iter_zones()
|
||||
.map_into()
|
||||
.map(Into::into)
|
||||
.chain(
|
||||
self.peers
|
||||
.iter()
|
||||
|
||||
@@ -4,7 +4,6 @@ use crate::proto::utils::RepeatedMessageModel;
|
||||
use anyhow::{anyhow, Error};
|
||||
use hickory_proto::xfer::Protocol;
|
||||
use hickory_resolver::config::{NameServerConfig, NameServerConfigGroup};
|
||||
use itertools::Itertools;
|
||||
use serde_with::{DeserializeFromStr, SerializeDisplay};
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
@@ -129,7 +128,7 @@ pub type NameServerAddrGroup = RepeatedMessageModel<NameServerAddr>;
|
||||
|
||||
impl From<NameServerAddrGroup> for NameServerConfigGroup {
|
||||
fn from(value: NameServerAddrGroup) -> Self {
|
||||
value.into_iter().map_into().collect_vec().into()
|
||||
value.into_iter().map(Into::into).collect::<Vec<_>>().into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,8 +137,8 @@ impl From<NameServerConfigGroup> for NameServerAddrGroup {
|
||||
value
|
||||
.into_inner()
|
||||
.into_iter()
|
||||
.map_into()
|
||||
.collect_vec()
|
||||
.map(Into::into)
|
||||
.collect::<Vec<_>>()
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use hickory_proto::rr::LowerName;
|
||||
use idna::AsciiDenyList;
|
||||
use itertools::Itertools;
|
||||
|
||||
pub mod addr;
|
||||
pub mod authority;
|
||||
@@ -24,7 +23,7 @@ pub fn sanitize(name: &str) -> String {
|
||||
.to_string()
|
||||
})
|
||||
.filter(|label| !label.is_empty())
|
||||
.collect_vec()
|
||||
.collect::<Vec<_>>()
|
||||
.join(".");
|
||||
name.truncate(253);
|
||||
if dot {
|
||||
|
||||
@@ -3,7 +3,6 @@ use crate::dns::utils::addr::NameServerAddr;
|
||||
use crate::dns::utils::authority::ArcAuthority;
|
||||
use crate::proto;
|
||||
use crate::proto::utils::RepeatedMessageModel;
|
||||
use crate::utils::MapTryInto;
|
||||
use hickory_proto::rr::{LowerName, RecordSet, RrKey};
|
||||
use hickory_proto::serialize::txt::Parser;
|
||||
use hickory_resolver::config::ResolverOpts;
|
||||
@@ -13,7 +12,7 @@ use hickory_server::authority::ZoneType;
|
||||
use hickory_server::store::forwarder::{ForwardAuthority, ForwardConfig};
|
||||
use hickory_server::store::in_memory::InMemoryAuthority;
|
||||
use indexmap::IndexMap;
|
||||
use itertools::{chain, Itertools};
|
||||
use itertools::chain;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
@@ -96,9 +95,9 @@ impl TryFrom<&proto::dns::ZoneData> for Zone {
|
||||
let servers = value
|
||||
.forwarders
|
||||
.iter()
|
||||
.map_try_into::<NameServerAddr>()
|
||||
.map_ok(Into::into)
|
||||
.try_collect::<_, Vec<_>, _>()?;
|
||||
.map(TryInto::<NameServerAddr>::try_into)
|
||||
.map(|a| a.map(Into::into))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let forward = (!servers.is_empty()).then_some(ForwardConfig {
|
||||
name_servers: servers.into(),
|
||||
options: None,
|
||||
@@ -126,8 +125,8 @@ impl From<Zone> for proto::dns::ZoneData {
|
||||
.forward
|
||||
.into_iter()
|
||||
.flat_map(|f| f.name_servers.into_inner().into_iter())
|
||||
.map_into::<NameServerAddr>()
|
||||
.map_into()
|
||||
.map(Into::<NameServerAddr>::into)
|
||||
.map(Into::into)
|
||||
.collect();
|
||||
|
||||
Self {
|
||||
@@ -365,7 +364,7 @@ mod tests {
|
||||
))?]
|
||||
.into();
|
||||
|
||||
let authorities = zones.iter_authorities().collect_vec();
|
||||
let authorities = zones.iter_authorities().collect::<Vec<_>>();
|
||||
assert_eq!(authorities.len(), 2);
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -73,7 +73,6 @@ use crate::{
|
||||
|
||||
use atomic_shim::AtomicU64;
|
||||
use cfg_if::cfg_if;
|
||||
use itertools::Itertools;
|
||||
|
||||
static SERVICE_ID: u32 = 7;
|
||||
static UPDATE_PEER_INFO_PERIOD: Duration = Duration::from_secs(3600);
|
||||
@@ -1341,7 +1340,7 @@ impl RouteTable {
|
||||
.into_iter()
|
||||
.flat_map(|info| &info.proxy_cidrs)
|
||||
.filter_map(|cidr| cidr.parse::<IpCidr>().ok())
|
||||
.collect_vec();
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// build next hop map
|
||||
let (graph, start_node) =
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
use crate::utils::MapTryInto;
|
||||
use derivative::Derivative;
|
||||
use derive_more::{Deref, DerefMut, From, IntoIterator};
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub trait MessageModel<Message: prost::Message>:
|
||||
@@ -49,7 +47,12 @@ where
|
||||
type Error = <Model as TryFrom<&'m Message>>::Error;
|
||||
|
||||
fn try_from(value: &'m Vec<Message>) -> Result<Self, Self::Error> {
|
||||
Ok(Self(value.iter().map_try_into().try_collect()?))
|
||||
Ok(Self(
|
||||
value
|
||||
.iter()
|
||||
.map(TryInto::try_into)
|
||||
.collect::<Result<_, _>>()?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +62,6 @@ where
|
||||
Model: MessageModel<Message>,
|
||||
{
|
||||
fn from(value: RepeatedMessageModel<Model>) -> Self {
|
||||
value.into_iter().map_into().collect()
|
||||
value.into_iter().map(Into::into).collect()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,17 +168,6 @@ pub trait DeterministicDigest: Serialize {
|
||||
|
||||
impl<S: Serialize> DeterministicDigest for S {}
|
||||
|
||||
pub trait MapTryInto: Iterator + Sized {
|
||||
fn map_try_into<R>(self) -> impl Iterator<Item = Result<R, <Self::Item as TryInto<R>>::Error>>
|
||||
where
|
||||
Self::Item: TryInto<R>,
|
||||
{
|
||||
self.into_iter().map(Self::Item::try_into)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> MapTryInto for T where T: Iterator + Sized {}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
enum AsyncRuntimeState<T> {
|
||||
#[default]
|
||||
|
||||
Reference in New Issue
Block a user