-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from moka-rs/remove-clone-from-key
Remove unnecessary `K: Clone` bound from some caches when they are `Clone`
- Loading branch information
Showing
15 changed files
with
430 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "moka" | ||
version = "0.8.4" | ||
version = "0.8.5" | ||
edition = "2018" | ||
rust-version = "1.51" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// https://github.com/moka-rs/moka/issues/131 | ||
|
||
use std::{collections::hash_map::DefaultHasher, hash::BuildHasher, sync::Arc}; | ||
|
||
use moka::dash::Cache; | ||
|
||
fn main() { | ||
f1_fail(); | ||
f2_pass(); | ||
f3_fail(); | ||
f4_pass(); | ||
} | ||
|
||
const CAP: u64 = 100; | ||
|
||
fn f1_fail() { | ||
// This should fail because V is not Clone. | ||
let _cache: Cache<MyKey, MyValue> = Cache::new(CAP); | ||
} | ||
|
||
fn f2_pass() { | ||
let cache: Cache<MyKey, Arc<MyValue>> = Cache::new(CAP); | ||
let _ = cache.clone(); | ||
} | ||
|
||
fn f3_fail() { | ||
// This should fail because S is not Clone. | ||
let _cache: Cache<MyKey, Arc<MyValue>, _> = Cache::builder().build_with_hasher(MyBuildHasher1); | ||
} | ||
|
||
fn f4_pass() { | ||
let cache: Cache<MyKey, Arc<MyValue>, _> = Cache::builder().build_with_hasher(MyBuildHasher2); | ||
let _ = cache.clone(); | ||
} | ||
|
||
// MyKey is not Clone. | ||
#[derive(Hash, PartialEq, Eq)] | ||
pub struct MyKey(i32); | ||
|
||
// MyValue is not Clone. | ||
pub struct MyValue(i32); | ||
|
||
// MyBuildHasher1 is not Clone. | ||
pub struct MyBuildHasher1; | ||
|
||
impl BuildHasher for MyBuildHasher1 { | ||
type Hasher = DefaultHasher; | ||
|
||
fn build_hasher(&self) -> Self::Hasher { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
// MyBuildHasher1 is Clone. | ||
#[derive(Clone)] | ||
pub struct MyBuildHasher2; | ||
|
||
impl BuildHasher for MyBuildHasher2 { | ||
type Hasher = DefaultHasher; | ||
|
||
fn build_hasher(&self) -> Self::Hasher { | ||
unimplemented!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error[E0277]: the trait bound `MyValue: Clone` is not satisfied | ||
--> tests/compile_tests/dash/clone/dash_cache_clone.rs:18:41 | ||
| | ||
18 | let _cache: Cache<MyKey, MyValue> = Cache::new(CAP); | ||
| ^^^^^^^^^^ the trait `Clone` is not implemented for `MyValue` | ||
| | ||
note: required by a bound in `moka::dash::Cache::<K, V>::new` | ||
--> src/dash/cache.rs | ||
| | ||
| V: Clone + Send + Sync + 'static, | ||
| ^^^^^ required by this bound in `moka::dash::Cache::<K, V>::new` | ||
|
||
error[E0277]: the trait bound `MyBuildHasher1: Clone` is not satisfied | ||
--> tests/compile_tests/dash/clone/dash_cache_clone.rs:28:84 | ||
| | ||
28 | let _cache: Cache<MyKey, Arc<MyValue>, _> = Cache::builder().build_with_hasher(MyBuildHasher1); | ||
| ----------------- ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `MyBuildHasher1` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `moka::dash::CacheBuilder::<K, V, moka::dash::Cache<K, V>>::build_with_hasher` | ||
--> src/dash/builder.rs | ||
| | ||
| S: BuildHasher + Clone + Send + Sync + 'static, | ||
| ^^^^^ required by this bound in `moka::dash::CacheBuilder::<K, V, moka::dash::Cache<K, V>>::build_with_hasher` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// https://github.com/moka-rs/moka/issues/131 | ||
|
||
use std::{collections::hash_map::DefaultHasher, hash::BuildHasher, sync::Arc}; | ||
|
||
use moka::sync::Cache; | ||
|
||
fn main() { | ||
f1_fail(); | ||
f2_pass(); | ||
f3_fail(); | ||
f4_pass(); | ||
} | ||
|
||
const CAP: u64 = 100; | ||
|
||
fn f1_fail() { | ||
// This should fail because V is not Clone. | ||
let _cache: Cache<MyKey, MyValue> = Cache::new(CAP); | ||
} | ||
|
||
fn f2_pass() { | ||
let cache: Cache<MyKey, Arc<MyValue>> = Cache::new(CAP); | ||
let _ = cache.clone(); | ||
} | ||
|
||
fn f3_fail() { | ||
// This should fail because S is not Clone. | ||
let _cache: Cache<MyKey, Arc<MyValue>, _> = Cache::builder().build_with_hasher(MyBuildHasher1); | ||
} | ||
|
||
fn f4_pass() { | ||
let cache: Cache<MyKey, Arc<MyValue>, _> = Cache::builder().build_with_hasher(MyBuildHasher2); | ||
let _ = cache.clone(); | ||
} | ||
|
||
// MyKey is not Clone. | ||
#[derive(Hash, PartialEq, Eq)] | ||
pub struct MyKey(i32); | ||
|
||
// MyValue is not Clone. | ||
pub struct MyValue(i32); | ||
|
||
// MyBuildHasher1 is not Clone. | ||
pub struct MyBuildHasher1; | ||
|
||
impl BuildHasher for MyBuildHasher1 { | ||
type Hasher = DefaultHasher; | ||
|
||
fn build_hasher(&self) -> Self::Hasher { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
// MyBuildHasher1 is Clone. | ||
#[derive(Clone)] | ||
pub struct MyBuildHasher2; | ||
|
||
impl BuildHasher for MyBuildHasher2 { | ||
type Hasher = DefaultHasher; | ||
|
||
fn build_hasher(&self) -> Self::Hasher { | ||
unimplemented!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error[E0277]: the trait bound `MyValue: Clone` is not satisfied | ||
--> tests/compile_tests/default/clone/sync_cache_clone.rs:18:41 | ||
| | ||
18 | let _cache: Cache<MyKey, MyValue> = Cache::new(CAP); | ||
| ^^^^^^^^^^ the trait `Clone` is not implemented for `MyValue` | ||
| | ||
note: required by a bound in `moka::sync::Cache::<K, V>::new` | ||
--> src/sync/cache.rs | ||
| | ||
| V: Clone + Send + Sync + 'static, | ||
| ^^^^^ required by this bound in `moka::sync::Cache::<K, V>::new` | ||
|
||
error[E0277]: the trait bound `MyBuildHasher1: Clone` is not satisfied | ||
--> tests/compile_tests/default/clone/sync_cache_clone.rs:28:84 | ||
| | ||
28 | let _cache: Cache<MyKey, Arc<MyValue>, _> = Cache::builder().build_with_hasher(MyBuildHasher1); | ||
| ----------------- ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `MyBuildHasher1` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
note: required by a bound in `moka::sync::CacheBuilder::<K, V, moka::sync::Cache<K, V>>::build_with_hasher` | ||
--> src/sync/builder.rs | ||
| | ||
| S: BuildHasher + Clone + Send + Sync + 'static, | ||
| ^^^^^ required by this bound in `moka::sync::CacheBuilder::<K, V, moka::sync::Cache<K, V>>::build_with_hasher` |
Oops, something went wrong.