From 35de0e5884f2ea7b6a5423ce3e10106a674f0d4b Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Thu, 8 Feb 2024 15:29:23 +0800 Subject: [PATCH] clippy fix. --- client/src/response.rs | 17 -------------- http-rate/src/state/in_memory.rs | 1 + http-rate/src/state/keyed.rs | 9 ++++---- http-rate/src/state/keyed/hashmap.rs | 5 +++-- http-rate/src/timer.rs | 8 ------- http/src/lib.rs | 1 + http/src/version.rs | 33 ++++++++++++---------------- 7 files changed, 23 insertions(+), 51 deletions(-) diff --git a/client/src/response.rs b/client/src/response.rs index 0e5f3ff9..be22e079 100644 --- a/client/src/response.rs +++ b/client/src/response.rs @@ -181,8 +181,6 @@ trait Collectable { fn with_capacity(cap: usize) -> Self; fn try_extend_from_slice(&mut self, slice: &[u8]) -> Result<(), Error>; - - fn len(&self) -> usize; } impl Collectable for BytesMut { @@ -196,11 +194,6 @@ impl Collectable for BytesMut { self.extend_from_slice(slice); Ok(()) } - - #[inline] - fn len(&self) -> usize { - Self::len(self) - } } impl Collectable for Vec { @@ -214,11 +207,6 @@ impl Collectable for Vec { self.extend_from_slice(slice); Ok(()) } - - #[inline] - fn len(&self) -> usize { - Self::len(self) - } } impl Collectable for String { @@ -232,9 +220,4 @@ impl Collectable for String { self.push_str(str); Ok(()) } - - #[inline] - fn len(&self) -> usize { - Self::len(self) - } } diff --git a/http-rate/src/state/in_memory.rs b/http-rate/src/state/in_memory.rs index 3ed8b698..32a539ff 100644 --- a/http-rate/src/state/in_memory.rs +++ b/http-rate/src/state/in_memory.rs @@ -42,6 +42,7 @@ impl InMemoryState { decision.map(|(result, _)| result) } + #[cfg(test)] pub(crate) fn is_older_than(&self, nanos: Nanos) -> bool { self.0.load(Ordering::Relaxed) <= nanos.into() } diff --git a/http-rate/src/state/keyed.rs b/http-rate/src/state/keyed.rs index 503f92b1..b124d45f 100644 --- a/http-rate/src/state/keyed.rs +++ b/http-rate/src/state/keyed.rs @@ -1,8 +1,6 @@ use core::hash::Hash; -use crate::{ - gcra::NotUntil, nanos::Nanos, quota::Quota, snapshot::RateSnapshot, state::RateLimiter, state::StateStore, timer, -}; +use crate::{gcra::NotUntil, quota::Quota, snapshot::RateSnapshot, state::RateLimiter, state::StateStore, timer}; #[cfg(test)] use core::num::NonZeroU32; @@ -87,6 +85,7 @@ where } } +#[cfg(test)] /// Keyed rate limiters that can be "cleaned up". /// /// Any keyed state store implementing this trait allows users to evict elements that are @@ -98,7 +97,7 @@ where /// shrinking. pub(crate) trait ShrinkableKeyedStateStore: KeyedStateStore { /// Remove those keys with state older than `drop_below`. - fn retain_recent(&self, drop_below: Nanos); + fn retain_recent(&self, drop_below: crate::nanos::Nanos); /// Shrinks the capacity of the state store, if possible. /// @@ -179,7 +178,7 @@ pub(crate) type DefaultKeyedStateStore = HashMapStateStore; mod test { use core::{marker::PhantomData, num::NonZeroU32}; - use crate::timer::FakeRelativeClock; + use crate::{nanos::Nanos, timer::FakeRelativeClock}; use super::*; diff --git a/http-rate/src/state/keyed/hashmap.rs b/http-rate/src/state/keyed/hashmap.rs index ea1c5320..c4d3e39f 100644 --- a/http-rate/src/state/keyed/hashmap.rs +++ b/http-rate/src/state/keyed/hashmap.rs @@ -4,7 +4,7 @@ use std::{collections::HashMap, sync::Mutex}; use crate::{ nanos::Nanos, - state::{keyed::ShrinkableKeyedStateStore, InMemoryState, StateStore}, + state::{InMemoryState, StateStore}, }; #[cfg(test)] @@ -38,7 +38,8 @@ where } } -impl ShrinkableKeyedStateStore for HashMapStateStore +#[cfg(test)] +impl crate::state::keyed::ShrinkableKeyedStateStore for HashMapStateStore where K: Hash + Eq + Clone, { diff --git a/http-rate/src/timer.rs b/http-rate/src/timer.rs index 6f027225..c5516174 100644 --- a/http-rate/src/timer.rs +++ b/http-rate/src/timer.rs @@ -134,14 +134,6 @@ impl Timer for DefaultTimer { } } -pub trait ReasonablyRealtime: Timer { - fn reference_point(&self) -> Self::Instant { - self.now() - } -} - -impl ReasonablyRealtime for DefaultTimer {} - #[cfg(test)] mod test { use super::*; diff --git a/http/src/lib.rs b/http/src/lib.rs index 57f573f3..c55f37f7 100644 --- a/http/src/lib.rs +++ b/http/src/lib.rs @@ -41,6 +41,7 @@ mod builder; #[cfg(feature = "runtime")] mod service; mod tls; +#[cfg(feature = "runtime")] mod version; pub mod body; diff --git a/http/src/version.rs b/http/src/version.rs index 98e320eb..1196333a 100644 --- a/http/src/version.rs +++ b/http/src/version.rs @@ -13,27 +13,22 @@ pub trait AsVersion { } } -#[cfg(feature = "runtime")] -mod io_impl { - use super::*; - - impl AsVersion for xitca_io::net::Stream { - #[inline] - fn as_version(&self) -> Version { - match *self { - Self::Tcp(..) => Version::HTTP_11, - #[cfg(unix)] - Self::Unix(..) => Version::HTTP_11, - #[cfg(feature = "http3")] - Self::Udp(..) => Version::HTTP_3, - } +impl AsVersion for xitca_io::net::Stream { + #[inline] + fn as_version(&self) -> Version { + match *self { + Self::Tcp(..) => Version::HTTP_11, + #[cfg(unix)] + Self::Unix(..) => Version::HTTP_11, + #[cfg(feature = "http3")] + Self::Udp(..) => Version::HTTP_3, } } +} - impl AsVersion for xitca_io::net::TcpStream { - #[inline] - fn as_version(&self) -> Version { - Version::HTTP_11 - } +impl AsVersion for xitca_io::net::TcpStream { + #[inline] + fn as_version(&self) -> Version { + Version::HTTP_11 } }