From cc28dda575cb5fa787c1bfe7d78fffa67ee4bebc Mon Sep 17 00:00:00 2001 From: "Peter C. S. Scholtens" Date: Thu, 4 May 2023 08:37:31 +0200 Subject: [PATCH] Removed unused Borrow trait requirements. Code aligned with rustfmt --edition 2021 --- benches/moka-rs/src/main.rs | 6 +++++- benches/ristretto-rs/src/main.rs | 4 +--- src/cache.rs | 6 ------ src/cache/builder.rs | 2 +- src/cache/test.rs | 3 --- src/lib.rs | 7 ------- 6 files changed, 7 insertions(+), 21 deletions(-) diff --git a/benches/moka-rs/src/main.rs b/benches/moka-rs/src/main.rs index cc2ae97..0f87caa 100644 --- a/benches/moka-rs/src/main.rs +++ b/benches/moka-rs/src/main.rs @@ -1,7 +1,11 @@ #[macro_use] extern crate serde; -use std::{fmt, hash::{BuildHasher, Hasher}, path::Path}; +use std::{ + fmt, + hash::{BuildHasher, Hasher}, + path::Path, +}; #[global_allocator] static GLOBAL_ALLOCATOR: mimalloc::MiMalloc = mimalloc::MiMalloc; diff --git a/benches/ristretto-rs/src/main.rs b/benches/ristretto-rs/src/main.rs index e432e53..3e2111c 100644 --- a/benches/ristretto-rs/src/main.rs +++ b/benches/ristretto-rs/src/main.rs @@ -3,7 +3,6 @@ extern crate serde; use std::path::Path; - #[global_allocator] static GLOBAL_ALLOCATOR: mimalloc::MiMalloc = mimalloc::MiMalloc; @@ -21,7 +20,6 @@ struct KV { cost: i64, } - #[cfg(feature = "sync")] fn main() -> Result<(), Box> { use std::fs; @@ -53,9 +51,9 @@ fn main() -> Result<(), Box> { #[cfg(feature = "async")] #[tokio::main] async fn main() -> Result<(), Box> { + use stretto::AsyncCache; use tokio::fs; use tokio::time::Instant; - use stretto::AsyncCache; let content = fs::read(Path::new("mock.json")).await?; let dataset: Dataset = serde_json::from_slice(content.as_slice())?; diff --git a/src/cache.rs b/src/cache.rs index dfd6d0d..74f3c36 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -217,7 +217,6 @@ macro_rules! impl_cache { /// value was found or not. pub fn get(&self, key: &Q) -> Option> where - K: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { if self.is_closed.load(Ordering::SeqCst) { @@ -244,7 +243,6 @@ macro_rules! impl_cache { /// value was found or not. pub fn get_mut(&self, key: &Q) -> Option> where - K: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { if self.is_closed.load(Ordering::SeqCst) { @@ -271,7 +269,6 @@ macro_rules! impl_cache { /// item was found and is not expired. pub fn get_ttl(&self, key: &Q) -> Option where - K: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { let (index, conflict) = self.key_to_hash.build_key(key); @@ -533,7 +530,6 @@ macro_rules! impl_async_cache { /// value was found or not. pub async fn get(&self, key: &Q) -> Option> where - K: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { if self.is_closed.load(Ordering::SeqCst) { @@ -560,7 +556,6 @@ macro_rules! impl_async_cache { /// value was found or not. pub async fn get_mut(&self, key: &Q) -> Option> where - K: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { if self.is_closed.load(Ordering::SeqCst) { @@ -587,7 +582,6 @@ macro_rules! impl_async_cache { /// item was found and is not expired. pub fn get_ttl(&self, key: &Q) -> Option where - K: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { let (index, conflict) = self.key_to_hash.build_key(key); diff --git a/src/cache/builder.rs b/src/cache/builder.rs index c79d218..4547d83 100644 --- a/src/cache/builder.rs +++ b/src/cache/builder.rs @@ -176,7 +176,7 @@ where /// This is a fine-tuning mechanism and you probably won't have to touch this. #[inline] pub fn set_buffer_size(mut self, sz: usize) -> Self { - self.insert_buffer_size = sz; + self.insert_buffer_size = sz; self } diff --git a/src/cache/test.rs b/src/cache/test.rs index 0a8cd9e..144ce23 100644 --- a/src/cache/test.rs +++ b/src/cache/test.rs @@ -35,7 +35,6 @@ impl KeyBuilder for KHTest { fn hash_index(&self, key: &Q) -> u64 where - Self::Key: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { let mut hasher = TransparentHasher { data: 0 }; @@ -45,7 +44,6 @@ impl KeyBuilder for KHTest { fn hash_conflict(&self, _key: &Q) -> u64 where - Self::Key: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { 0 @@ -53,7 +51,6 @@ impl KeyBuilder for KHTest { fn build_key(&self, k: &Q) -> (u64, u64) where - Self::Key: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { self.ctr.fetch_add(1, Ordering::SeqCst); diff --git a/src/lib.rs b/src/lib.rs index 0292209..27754c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -445,14 +445,12 @@ pub trait KeyBuilder { /// `hash_index` is used to hash the key to u64 fn hash_index(&self, key: &Q) -> u64 where - Self::Key: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized; /// if you want a 128bit hashes, you should implement this method, /// or leave this method return 0 fn hash_conflict(&self, key: &Q) -> u64 where - Self::Key: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { let _ = key; @@ -462,7 +460,6 @@ pub trait KeyBuilder { /// build the key to 128bit hashes. fn build_key(&self, k: &Q) -> (u64, u64) where - Self::Key: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { (self.hash_index(k), self.hash_conflict(k)) @@ -510,7 +507,6 @@ impl KeyBuilder for DefaultKeyBuilder { #[inline] fn hash_index(&self, key: &Q) -> u64 where - Self::Key: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { let mut s = self.sea.build_hasher(); @@ -521,7 +517,6 @@ impl KeyBuilder for DefaultKeyBuilder { #[inline] fn hash_conflict(&self, key: &Q) -> u64 where - Self::Key: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { let mut x = self.xx.build_hasher(); @@ -634,7 +629,6 @@ impl KeyBuilder for TransparentKeyBuilder { #[inline] fn hash_index(&self, key: &Q) -> u64 where - Self::Key: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { let mut hasher = TransparentHasher { data: 0 }; @@ -645,7 +639,6 @@ impl KeyBuilder for TransparentKeyBuilder { #[inline] fn hash_conflict(&self, _key: &Q) -> u64 where - Self::Key: core::borrow::Borrow, Q: core::hash::Hash + Eq + ?Sized, { 0