Skip to content

Commit

Permalink
clippy fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow committed Feb 8, 2024
1 parent d7fa904 commit 35de0e5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 51 deletions.
17 changes: 0 additions & 17 deletions client/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<u8> {
Expand All @@ -214,11 +207,6 @@ impl Collectable for Vec<u8> {
self.extend_from_slice(slice);
Ok(())
}

#[inline]
fn len(&self) -> usize {
Self::len(self)
}
}

impl Collectable for String {
Expand All @@ -232,9 +220,4 @@ impl Collectable for String {
self.push_str(str);
Ok(())
}

#[inline]
fn len(&self) -> usize {
Self::len(self)
}
}
1 change: 1 addition & 0 deletions http-rate/src/state/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
9 changes: 4 additions & 5 deletions http-rate/src/state/keyed.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -98,7 +97,7 @@ where
/// shrinking.
pub(crate) trait ShrinkableKeyedStateStore<K: Hash>: KeyedStateStore<K> {
/// 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.
///
Expand Down Expand Up @@ -179,7 +178,7 @@ pub(crate) type DefaultKeyedStateStore<K> = HashMapStateStore<K>;
mod test {
use core::{marker::PhantomData, num::NonZeroU32};

use crate::timer::FakeRelativeClock;
use crate::{nanos::Nanos, timer::FakeRelativeClock};

use super::*;

Expand Down
5 changes: 3 additions & 2 deletions http-rate/src/state/keyed/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{collections::HashMap, sync::Mutex};

use crate::{
nanos::Nanos,
state::{keyed::ShrinkableKeyedStateStore, InMemoryState, StateStore},
state::{InMemoryState, StateStore},
};

#[cfg(test)]
Expand Down Expand Up @@ -38,7 +38,8 @@ where
}
}

impl<K> ShrinkableKeyedStateStore<K> for HashMapStateStore<K>
#[cfg(test)]
impl<K> crate::state::keyed::ShrinkableKeyedStateStore<K> for HashMapStateStore<K>
where
K: Hash + Eq + Clone,
{
Expand Down
8 changes: 0 additions & 8 deletions http-rate/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
1 change: 1 addition & 0 deletions http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ mod builder;
#[cfg(feature = "runtime")]
mod service;
mod tls;
#[cfg(feature = "runtime")]
mod version;

pub mod body;
Expand Down
33 changes: 14 additions & 19 deletions http/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 35de0e5

Please sign in to comment.