diff --git a/clash_lib/src/app/dispatcher/tracked.rs b/clash_lib/src/app/dispatcher/tracked.rs index b6bc9491e..4e7ba27d1 100644 --- a/clash_lib/src/app/dispatcher/tracked.rs +++ b/clash_lib/src/app/dispatcher/tracked.rs @@ -119,11 +119,12 @@ pub struct TrackedStream { } impl TrackedStream { + #[allow(clippy::borrowed_box)] pub async fn new( inner: BoxedChainedStream, manager: Arc, sess: Session, - #[allow(clippy::borrowed_box)] rule: Option<&Box>, + rule: Option<&Box>, ) -> Self { let uuid = uuid::Uuid::new_v4(); let chain = inner.chain().clone(); @@ -355,11 +356,12 @@ pub struct TrackedDatagram { } impl TrackedDatagram { + #[allow(clippy::borrowed_box)] pub async fn new( inner: BoxedChainedDatagram, manager: Arc, sess: Session, - #[allow(clippy::borrowed_box)] rule: Option<&Box>, + rule: Option<&Box>, ) -> Self { let uuid = uuid::Uuid::new_v4(); let chain = inner.chain().clone(); diff --git a/clash_lib/src/app/dns/config.rs b/clash_lib/src/app/dns/config.rs index 2e3cb3d16..5f8deca80 100644 --- a/clash_lib/src/app/dns/config.rs +++ b/clash_lib/src/app/dns/config.rs @@ -150,7 +150,7 @@ impl Config { let mut policy = HashMap::new(); for (domain, server) in policy_map { - let nameservers = Config::parse_nameserver(&vec![server.to_owned()])?; + let nameservers = Config::parse_nameserver(&[server.to_owned()])?; let (_, valid) = trie::valid_and_split_domain(domain); if !valid { diff --git a/clash_lib/src/app/outbound/manager.rs b/clash_lib/src/app/outbound/manager.rs index cb6d04752..05a2ccfeb 100644 --- a/clash_lib/src/app/outbound/manager.rs +++ b/clash_lib/src/app/outbound/manager.rs @@ -54,8 +54,8 @@ pub type ThreadSafeOutboundManager = Arc; impl OutboundManager { pub async fn new( - outbounds: Vec>, - outbound_groups: Vec>, + outbounds: Vec, + outbound_groups: Vec, proxy_providers: HashMap, proxy_names: Vec, dns_resolver: ThreadSafeDNSResolver, @@ -174,8 +174,8 @@ impl OutboundManager { #[allow(clippy::too_many_arguments)] async fn load_handlers( - outbounds: Vec>, - outbound_groups: Vec>, + outbounds: Vec, + outbound_groups: Vec, proxy_names: Vec, proxy_manager: ProxyManager, provider_registry: &mut HashMap, @@ -186,7 +186,7 @@ impl OutboundManager { let mut proxy_providers = vec![]; for outbound in outbounds.iter() { - match outbound.as_ref() { + match outbound { OutboundProxyProtocol::Direct => { handlers.insert(PROXY_DIRECT.to_string(), direct::Handler::new()); } @@ -269,7 +269,7 @@ impl OutboundManager { } for outbound_group in outbound_groups.iter() { - match outbound_group.as_ref() { + match outbound_group { OutboundGroupProtocol::Relay(proto) => { if proto.proxies.as_ref().map(|x| x.len()).unwrap_or_default() + proto diff --git a/clash_lib/src/app/outbound/utils.rs b/clash_lib/src/app/outbound/utils.rs index f9e87349b..ef94e5df2 100644 --- a/clash_lib/src/app/outbound/utils.rs +++ b/clash_lib/src/app/outbound/utils.rs @@ -6,12 +6,12 @@ use std::{ use crate::{config::internal::proxy::OutboundGroupProtocol, Error}; // copy paste from https://github.com/Dreamacro/clash/blob/6a661bff0c185f38c4bd9d21c91a3233ba5fdb97/config/utils.go#L21 -pub fn proxy_groups_dag_sort(groups: &mut Vec>) -> Result<(), Error> { +pub fn proxy_groups_dag_sort(groups: &mut Vec) -> Result<(), Error> { struct Node { in_degree: i32, // could be either group/proxy - proto: Option>, + proto: Option, outdegree: i32, @@ -222,7 +222,6 @@ mod tests { OutboundGroupProtocol::Select(g5), ] .into_iter() - .map(|x| Box::new(x) as Box) .collect(); super::proxy_groups_dag_sort(&mut groups).unwrap(); @@ -266,7 +265,6 @@ mod tests { OutboundGroupProtocol::Fallback(g3), ] .into_iter() - .map(|x| Box::new(x) as Box) .collect(); let e = super::proxy_groups_dag_sort(&mut groups).unwrap_err(); diff --git a/clash_lib/src/config/internal/config.rs b/clash_lib/src/config/internal/config.rs index 6f24f01ae..3b5e2393b 100644 --- a/clash_lib/src/config/internal/config.rs +++ b/clash_lib/src/config/internal/config.rs @@ -138,16 +138,15 @@ impl TryFrom for Config { HashMap::from([ ( String::from(PROXY_DIRECT), - OutboundProxy::ProxyServer(Box::new(OutboundProxyProtocol::Direct)), + OutboundProxy::ProxyServer(OutboundProxyProtocol::Direct), ), ( String::from(PROXY_REJECT), - OutboundProxy::ProxyServer(Box::new(OutboundProxyProtocol::Reject)), + OutboundProxy::ProxyServer(OutboundProxyProtocol::Reject), ), ]), |mut rv, x| { - let proxy = - OutboundProxy::ProxyServer(Box::new(OutboundProxyProtocol::try_from(x)?)); + let proxy = OutboundProxy::ProxyServer(OutboundProxyProtocol::try_from(x)?); let name = proxy.name(); if rv.contains_key(name.as_str()) { return Err(Error::InvalidConfig(format!( @@ -163,8 +162,8 @@ impl TryFrom for Config { proxy_groups: c.proxy_group.into_iter().try_fold( HashMap::::new(), |mut rv, mapping| { - let group = OutboundProxy::ProxyGroup(Box::new( - mapping.clone().try_into().map_err(|x: Error| { + let group = OutboundProxy::ProxyGroup(mapping.clone().try_into().map_err( + |x: Error| { if let Some(name) = mapping.get("name") { Error::InvalidConfig(format!( "proxy group: {}: {}", @@ -174,8 +173,8 @@ impl TryFrom for Config { } else { Error::InvalidConfig("proxy group name missing".to_string()) } - })?, - )); + }, + )?); proxy_names.push(group.name()); rv.insert(group.name().to_string(), group); Ok::, Error>(rv) diff --git a/clash_lib/src/config/internal/proxy.rs b/clash_lib/src/config/internal/proxy.rs index e12ae16bb..e934a06a0 100644 --- a/clash_lib/src/config/internal/proxy.rs +++ b/clash_lib/src/config/internal/proxy.rs @@ -11,9 +11,10 @@ pub const PROXY_DIRECT: &str = "DIRECT"; pub const PROXY_REJECT: &str = "REJECT"; pub const PROXY_GLOBAL: &str = "GLOBAL"; +#[allow(clippy::large_enum_variant)] pub enum OutboundProxy { - ProxyServer(Box), - ProxyGroup(Box), + ProxyServer(OutboundProxyProtocol), + ProxyGroup(OutboundGroupProtocol), } impl OutboundProxy { diff --git a/clash_lib/src/proxy/datagram.rs b/clash_lib/src/proxy/datagram.rs index 50f714fcd..15f026124 100644 --- a/clash_lib/src/proxy/datagram.rs +++ b/clash_lib/src/proxy/datagram.rs @@ -142,6 +142,7 @@ pub struct OutboundDatagramImpl { } impl OutboundDatagramImpl { + #[allow(clippy::new_ret_no_self)] pub fn new(udp: UdpSocket, resolver: ThreadSafeDNSResolver) -> AnyOutboundDatagram { let s = Self { inner: udp, diff --git a/clash_lib/src/proxy/shadowsocks/mod.rs b/clash_lib/src/proxy/shadowsocks/mod.rs index 49a95c433..f3e42e743 100644 --- a/clash_lib/src/proxy/shadowsocks/mod.rs +++ b/clash_lib/src/proxy/shadowsocks/mod.rs @@ -150,6 +150,7 @@ pub struct Handler { } impl Handler { + #[allow(clippy::new_ret_no_self)] pub fn new(opts: HandlerOptions) -> AnyOutboundHandler { Arc::new(Self { opts }) }