Skip to content

Commit

Permalink
Removed unused Borrow trait requirements. Code aligned with rustfmt -…
Browse files Browse the repository at this point in the history
…-edition 2021
  • Loading branch information
peter-scholtens committed May 4, 2023
1 parent 18a12c9 commit cc28dda
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 21 deletions.
6 changes: 5 additions & 1 deletion benches/moka-rs/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 1 addition & 3 deletions benches/ristretto-rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ extern crate serde;

use std::path::Path;


#[global_allocator]
static GLOBAL_ALLOCATOR: mimalloc::MiMalloc = mimalloc::MiMalloc;

Expand All @@ -21,7 +20,6 @@ struct KV {
cost: i64,
}


#[cfg(feature = "sync")]
fn main() -> Result<(), Box<dyn std::error::Error>> {
use std::fs;
Expand Down Expand Up @@ -53,9 +51,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "async")]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
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())?;
Expand Down
6 changes: 0 additions & 6 deletions src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ macro_rules! impl_cache {
/// value was found or not.
pub fn get<Q>(&self, key: &Q) -> Option<ValueRef<V, S>>
where
K: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
if self.is_closed.load(Ordering::SeqCst) {
Expand All @@ -244,7 +243,6 @@ macro_rules! impl_cache {
/// value was found or not.
pub fn get_mut<Q>(&self, key: &Q) -> Option<ValueRefMut<V, S>>
where
K: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
if self.is_closed.load(Ordering::SeqCst) {
Expand All @@ -271,7 +269,6 @@ macro_rules! impl_cache {
/// item was found and is not expired.
pub fn get_ttl<Q>(&self, key: &Q) -> Option<Duration>
where
K: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
let (index, conflict) = self.key_to_hash.build_key(key);
Expand Down Expand Up @@ -533,7 +530,6 @@ macro_rules! impl_async_cache {
/// value was found or not.
pub async fn get<Q>(&self, key: &Q) -> Option<ValueRef<V, S>>
where
K: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
if self.is_closed.load(Ordering::SeqCst) {
Expand All @@ -560,7 +556,6 @@ macro_rules! impl_async_cache {
/// value was found or not.
pub async fn get_mut<Q>(&self, key: &Q) -> Option<ValueRefMut<V, S>>
where
K: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
if self.is_closed.load(Ordering::SeqCst) {
Expand All @@ -587,7 +582,6 @@ macro_rules! impl_async_cache {
/// item was found and is not expired.
pub fn get_ttl<Q>(&self, key: &Q) -> Option<Duration>
where
K: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
let (index, conflict) = self.key_to_hash.build_key(key);
Expand Down
2 changes: 1 addition & 1 deletion src/cache/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 0 additions & 3 deletions src/cache/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ impl KeyBuilder for KHTest {

fn hash_index<Q>(&self, key: &Q) -> u64
where
Self::Key: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
let mut hasher = TransparentHasher { data: 0 };
Expand All @@ -45,15 +44,13 @@ impl KeyBuilder for KHTest {

fn hash_conflict<Q>(&self, _key: &Q) -> u64
where
Self::Key: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
0
}

fn build_key<Q>(&self, k: &Q) -> (u64, u64)
where
Self::Key: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
self.ctr.fetch_add(1, Ordering::SeqCst);
Expand Down
7 changes: 0 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,14 +445,12 @@ pub trait KeyBuilder {
/// `hash_index` is used to hash the key to u64
fn hash_index<Q>(&self, key: &Q) -> u64
where
Self::Key: core::borrow::Borrow<Q>,
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<Q>(&self, key: &Q) -> u64
where
Self::Key: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
let _ = key;
Expand All @@ -462,7 +460,6 @@ pub trait KeyBuilder {
/// build the key to 128bit hashes.
fn build_key<Q>(&self, k: &Q) -> (u64, u64)
where
Self::Key: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
(self.hash_index(k), self.hash_conflict(k))
Expand Down Expand Up @@ -510,7 +507,6 @@ impl<K: Hash + Eq> KeyBuilder for DefaultKeyBuilder<K> {
#[inline]
fn hash_index<Q>(&self, key: &Q) -> u64
where
Self::Key: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
let mut s = self.sea.build_hasher();
Expand All @@ -521,7 +517,6 @@ impl<K: Hash + Eq> KeyBuilder for DefaultKeyBuilder<K> {
#[inline]
fn hash_conflict<Q>(&self, key: &Q) -> u64
where
Self::Key: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
let mut x = self.xx.build_hasher();
Expand Down Expand Up @@ -634,7 +629,6 @@ impl<K: TransparentKey> KeyBuilder for TransparentKeyBuilder<K> {
#[inline]
fn hash_index<Q>(&self, key: &Q) -> u64
where
Self::Key: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
let mut hasher = TransparentHasher { data: 0 };
Expand All @@ -645,7 +639,6 @@ impl<K: TransparentKey> KeyBuilder for TransparentKeyBuilder<K> {
#[inline]
fn hash_conflict<Q>(&self, _key: &Q) -> u64
where
Self::Key: core::borrow::Borrow<Q>,
Q: core::hash::Hash + Eq + ?Sized,
{
0
Expand Down

0 comments on commit cc28dda

Please sign in to comment.