Skip to content

Commit

Permalink
enable more features in rustfmt.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
SKTT1Ryze committed Jun 29, 2024
1 parent f94970d commit 8167a2a
Show file tree
Hide file tree
Showing 24 changed files with 55 additions and 27 deletions.
4 changes: 1 addition & 3 deletions clash_lib/src/app/api/middlewares/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ where
S: Service<Request<Body>, Response = Response> + Send + 'static,
S::Future: Send + 'static,
{
type Response = S::Response;

type Error = S::Error;

type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
type Response = S::Response;

fn poll_ready(
&mut self,
Expand Down
6 changes: 3 additions & 3 deletions clash_lib/src/app/dispatcher/dispatcher_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Dispatcher {
sess
}
}
crate::session::SocksAddr::Domain(_, _) => sess,
crate::session::SocksAddr::Domain(..) => sess,
}
} else {
sess
Expand Down Expand Up @@ -287,7 +287,7 @@ impl Dispatcher {
sess
}
}
crate::session::SocksAddr::Domain(_, _) => sess,
crate::session::SocksAddr::Domain(..) => sess,
}
} else {
sess
Expand Down Expand Up @@ -597,7 +597,7 @@ impl Drop for OutboundHandleMap {
"dropping inner outbound handle map that has {} sessions",
self.0.len()
);
for (_, (recv_handle, send_handle, _, _)) in self.0.drain() {
for (_, (recv_handle, send_handle, ..)) in self.0.drain() {
recv_handle.abort();
send_handle.abort();
}
Expand Down
1 change: 1 addition & 0 deletions clash_lib/src/app/dispatcher/tracked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ where
T: Sink<UdpPacket, Error = std::io::Error> + Unpin,
{
type Error = std::io::Error;

fn poll_ready(
self: Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
Expand Down
1 change: 1 addition & 0 deletions clash_lib/src/app/dns/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ impl ClashResolver for Resolver {
.map(|ip| ip.map(net::IpAddr::from)),
}
}

async fn resolve_v4(
&self,
host: &str,
Expand Down
1 change: 1 addition & 0 deletions clash_lib/src/app/dns/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl ClashResolver for SystemResolver {
})
.choose(&mut rand::thread_rng()))
}

async fn resolve_v6(
&self,
host: &str,
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/app/remote_content_manager/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use crate::{
pub struct LocalConnector(pub AnyOutboundHandler, pub ThreadSafeDNSResolver);

impl Service<Uri> for LocalConnector {
type Response = BoxedChainedStream;
type Error = std::io::Error;
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
type Response = BoxedChainedStream;

fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ where
on_update: on_update.map(|f| Arc::new(Mutex::new(f))),
}
}

pub fn name(&self) -> &str {
self.name.as_str()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ impl Provider for PlainProvider {
fn name(&self) -> &str {
&self.name
}

fn vehicle_type(&self) -> ProviderVehicleType {
ProviderVehicleType::Compatible
}

fn typ(&self) -> ProviderType {
ProviderType::Proxy
}

async fn initialize(&self) -> std::io::Result<()> {
Ok(())
}

async fn update(&self) -> std::io::Result<()> {
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl RuleProvider for RuleProviderImpl {
}
}
}

fn behavior(&self) -> RuleSetBehavior {
self.behavior
}
Expand All @@ -177,12 +178,15 @@ impl Provider for RuleProviderImpl {
fn name(&self) -> &str {
self.fetcher.name()
}

fn vehicle_type(&self) -> ProviderVehicleType {
self.fetcher.vehicle_type()
}

fn typ(&self) -> ProviderType {
ProviderType::Rule
}

async fn initialize(&self) -> std::io::Result<()> {
let ele = self.fetcher.initial().await.map_err(map_io_error)?;
debug!("initializing rule provider {}", self.name());
Expand All @@ -191,6 +195,7 @@ impl Provider for RuleProviderImpl {
}
Ok(())
}

async fn update(&self) -> std::io::Result<()> {
let (ele, same) = self.fetcher.update().await.map_err(map_io_error)?;
debug!("rule provider {} updated. same? {}", self.name(), same);
Expand Down
3 changes: 2 additions & 1 deletion clash_lib/src/app/router/rules/geoip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ impl RuleMatcher for GeoIP {
false
}
},
crate::session::SocksAddr::Domain(_, _) => false,
crate::session::SocksAddr::Domain(..) => false,
}
}

fn target(&self) -> &str {
self.target.as_str()
}
Expand Down
3 changes: 2 additions & 1 deletion clash_lib/src/app/router/rules/ipcidr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ impl RuleMatcher for IpCidr {
true => self.ipnet.contains(&sess.source.ip()),
false => match &sess.destination {
SocksAddr::Ip(ip) => self.ipnet.contains(&ip.ip()),
SocksAddr::Domain(_, _) => false,
SocksAddr::Domain(..) => false,
},
}
}

fn target(&self) -> &str {
self.target.as_str()
}
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/common/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ use crate::{
pub struct LocalConnector(pub ThreadSafeDNSResolver);

impl Service<Uri> for LocalConnector {
type Response = AnyStream;
type Error = std::io::Error;
type Future =
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
type Response = AnyStream;

fn poll_ready(&mut self, _: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
Poll::Ready(Ok(()))
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/proxy/http/inbound/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ impl Connector {
}

impl tower::Service<Uri> for Connector {
type Response = AnyStream;
type Error = ProxyError;
type Future =
Pin<Box<dyn Future<Output = Result<AnyStream, Self::Error>> + Send>>;
type Response = AnyStream;

fn poll_ready(
&mut self,
Expand Down
4 changes: 1 addition & 3 deletions clash_lib/src/proxy/http/inbound/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,9 @@ struct ProxyService {
}

impl Service<Request<Body>> for ProxyService {
type Response = Response<Body>;

type Error = ProxyError;

type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;
type Response = Response<Body>;

fn poll_ready(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/proxy/shadowsocks/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl Stream for OutboundDatagramShadowsocks {
debug!("recv udp packet from remote ss server: {:?}", rv);

match rv {
Ok((n, src, _, _)) => Poll::Ready(Some(UdpPacket {
Ok((n, src, ..)) => Poll::Ready(Some(UdpPacket {
data: buf.filled()[..n].to_vec(),
src_addr: src.into(),
dst_addr: SocksAddr::any_ipv4(),
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/proxy/shadowsocks/shadow_tls/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub(crate) fn support_tls13(frame: &[u8]) -> bool {
}
let mut cursor = std::io::Cursor::new(&frame[SESSION_ID_LEN_IDX..]);
macro_rules! read_ok {
($res: expr) => {
($res:expr) => {
match $res {
Ok(r) => r,
Err(_) => {
Expand Down
2 changes: 1 addition & 1 deletion clash_lib/src/proxy/socks/inbound/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ impl Encoder<(Bytes, SocksAddr)> for Socks5UDPCodec {
}

impl Decoder for Socks5UDPCodec {
type Item = (SocksAddr, BytesMut);
type Error = std::io::Error;
type Item = (SocksAddr, BytesMut);

fn decode(
&mut self,
Expand Down
5 changes: 5 additions & 0 deletions clash_lib/src/proxy/tuic/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use super::TuicDatagramOutbound;

impl Sink<UdpPacket> for TuicDatagramOutbound {
type Error = std::io::Error;

fn poll_ready(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand All @@ -19,6 +20,7 @@ impl Sink<UdpPacket> for TuicDatagramOutbound {
.poll_ready_unpin(cx)
.map_err(|v| new_io_error(&format!("{v:?}")))
}

fn start_send(
mut self: Pin<&mut Self>,
item: UdpPacket,
Expand All @@ -27,6 +29,7 @@ impl Sink<UdpPacket> for TuicDatagramOutbound {
.start_send_unpin(item)
.map_err(|v| new_io_error(&format!("{v:?}")))
}

fn poll_flush(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand All @@ -35,6 +38,7 @@ impl Sink<UdpPacket> for TuicDatagramOutbound {
.poll_flush_unpin(cx)
.map_err(|v| new_io_error(&format!("{v:?}")))
}

fn poll_close(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand All @@ -47,6 +51,7 @@ impl Sink<UdpPacket> for TuicDatagramOutbound {

impl Stream for TuicDatagramOutbound {
type Item = UdpPacket;

fn poll_next(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand Down
1 change: 1 addition & 0 deletions clash_lib/src/proxy/tuic/handle_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ impl TuicConnection {
self.inner.collect_garbage(gc_lifetime);
Ok(())
}

/// Tasks triggered by timer
/// Won't return unless occurs error
pub async fn cyclical_tasks(
Expand Down
1 change: 1 addition & 0 deletions clash_lib/src/proxy/tuic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl OutboundHandler for Handler {
std::io::Error::new(std::io::ErrorKind::Other, e.to_string())
})
}

async fn connect_datagram(
&self,
sess: &Session,
Expand Down
2 changes: 2 additions & 0 deletions clash_lib/src/proxy/tuic/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl TuicConnection {
None => Ok(()),
}
}

#[allow(clippy::too_many_arguments)]
fn new(
conn: QuinnConnection,
Expand Down Expand Up @@ -161,6 +162,7 @@ impl TuicConnection {

conn
}

async fn init(
self: Arc<Self>,
zero_rtt_accepted: Option<ZeroRttAccepted>,
Expand Down
1 change: 1 addition & 0 deletions clash_lib/src/proxy/vmess/vmess_impl/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ impl VmessSecurity {
pub fn overhead_len(&self) -> usize {
16
}

#[inline(always)]
pub fn nonce_len(&self) -> usize {
12
Expand Down
8 changes: 4 additions & 4 deletions clash_lib/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl Display for SocksAddr {
pub struct SocksAddrType;

impl SocksAddrType {
pub const V4: u8 = 0x1;
pub const DOMAIN: u8 = 0x3;
pub const V4: u8 = 0x1;
pub const V6: u8 = 0x4;
}

Expand Down Expand Up @@ -97,7 +97,7 @@ impl SocksAddr {
pub fn is_domain(&self) -> bool {
match self {
SocksAddr::Ip(_) => false,
SocksAddr::Domain(_, _) => true,
SocksAddr::Domain(..) => true,
}
}

Expand All @@ -111,7 +111,7 @@ impl SocksAddr {
pub fn must_into_socket_addr(self) -> SocketAddr {
match self {
SocksAddr::Ip(addr) => addr,
SocksAddr::Domain(_, _) => panic!("not a socket address"),
SocksAddr::Domain(..) => panic!("not a socket address"),
}
}

Expand Down Expand Up @@ -344,7 +344,7 @@ impl TryFrom<SocksAddr> for SocketAddr {
fn try_from(s: SocksAddr) -> Result<Self, Self::Error> {
match s {
SocksAddr::Ip(ip) => Ok(ip),
SocksAddr::Domain(_, _) => {
SocksAddr::Domain(..) => {
Err(io::Error::new(io::ErrorKind::Other, "cannot convert"))
}
}
Expand Down
19 changes: 13 additions & 6 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
error_on_line_overflow = false
edition = "2021"
reorder_modules = true
reorder_impl_items = true
reorder_imports = true
format_strings = true
format_code_in_doc_comments = true
format_macro_matchers = true
condense_wildcard_suffixes = true
normalize_comments = true
imports_granularity = "Crate"
reorder_modules = true
max_width = 85
# enum_discrim_align_threshold = 20
use_try_shorthand = true
wrap_comments = true
edition = "2021"
use_field_init_shorthand = true
error_on_line_overflow = false
tab_spaces = 4
enum_discrim_align_threshold = 20
max_width = 85
imports_granularity = "Crate"

0 comments on commit 8167a2a

Please sign in to comment.