Skip to content

Commit

Permalink
Merge pull request #22 from goldwind-ting/feat-deletetraitbound
Browse files Browse the repository at this point in the history
fix #4: delete bounds in the struct definition
  • Loading branch information
al8n authored May 22, 2022
2 parents 05bf1bc + c702a4f commit 85c551b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 53 deletions.
17 changes: 3 additions & 14 deletions src/cache/axync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ use crate::ttl::{ExpirationMap, Time};
/// [`Coster`]: trait.Coster.html
#[cfg_attr(docsrs, doc(cfg(feature = "async")))]
pub struct AsyncCacheBuilder<
K: Hash + Eq,
V: Send + Sync + 'static,
K,
V,
KH = DefaultKeyBuilder,
C = DefaultCoster<V>,
U = DefaultUpdateValidator<V>,
Expand Down Expand Up @@ -233,11 +233,6 @@ impl<K, V, KH, C, U, CB, S> AsyncCacheBuilder<K, V, KH, C, U, CB, S>
}

pub(crate) struct CacheProcessor<V, U, CB, S>
where
V: Send + Sync + 'static,
U: UpdateValidator<V>,
CB: CacheCallback<V>,
S: BuildHasher + Clone + 'static,
{
insert_buf_rx: Receiver<Item<V>>,
stop_rx: Receiver<()>,
Expand All @@ -253,13 +248,7 @@ pub(crate) struct CacheProcessor<V, U, CB, S>
cleanup_duration: Duration,
}

pub(crate) struct CacheCleaner<'a, V, U, CB, S>
where
V: Send + Sync + 'static,
U: UpdateValidator<V>,
CB: CacheCallback<V>,
S: BuildHasher + Clone + 'static,
{
pub(crate) struct CacheCleaner<'a, V, U, CB, S>{
pub(crate) processor: &'a mut CacheProcessor<V, U, CB, S>,
}

Expand Down
4 changes: 2 additions & 2 deletions src/cache/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::marker::PhantomData;
use std::time::Duration;

pub struct CacheBuilderCore<
K: Hash + Eq,
V: Send + Sync + 'static,
K,
V,
KH = DefaultKeyBuilder,
C = DefaultCoster<V>,
U = DefaultUpdateValidator<V>,
Expand Down
25 changes: 5 additions & 20 deletions src/cache/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ use std::time::Duration;
/// [`CacheCallback`]: trait.CacheCallback.html
/// [`Coster`]: trait.Coster.html
pub struct CacheBuilder<
K: Hash + Eq,
V: Send + Sync + 'static,
K,
V,
KH = DefaultKeyBuilder,
C = DefaultCoster<V>,
U = DefaultUpdateValidator<V>,
Expand Down Expand Up @@ -286,13 +286,7 @@ impl<V> Item<V> {
}
}

pub(crate) struct CacheProcessor<V, U, CB, S>
where
V: Send + Sync + 'static,
U: UpdateValidator<V>,
CB: CacheCallback<V>,
S: BuildHasher + Clone + 'static + Send,
{
pub(crate) struct CacheProcessor<V, U, CB, S>{
pub(crate) insert_buf_rx: Receiver<Item<V>>,
pub(crate) stop_rx: Receiver<()>,
pub(crate) clear_rx: UnboundedReceiver<()>,
Expand All @@ -307,13 +301,7 @@ where
pub(crate) cleanup_duration: Duration,
}

pub(crate) struct CacheCleaner<'a, V, U, CB, S>
where
V: Send + Sync + 'static,
U: UpdateValidator<V>,
CB: CacheCallback<V>,
S: BuildHasher + Clone + 'static + Send,
{
pub(crate) struct CacheCleaner<'a, V, U, CB, S>{
pub(crate) processor: &'a mut CacheProcessor<V, U, CB, S>,
}

Expand Down Expand Up @@ -346,10 +334,7 @@ pub struct Cache<
U = DefaultUpdateValidator<V>,
CB = DefaultCacheCallback<V>,
S = RandomState,
> where
K: Hash + Eq,
V: Send + Sync + 'static,
{
>{
/// store is the central concurrent hashmap where key-value items are stored.
pub(crate) store: Arc<ShardedMap<V, U, S, S>>,

Expand Down
11 changes: 5 additions & 6 deletions src/cache/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,15 +696,14 @@ mod sync_test {
fn test_valueref_ttl() {
let ttl = Duration::from_secs(1);
let c = Cache::builder(100, 1000)
.set_key_builder(TransparentKeyBuilder::default())
.set_metrics(true)
.finalize()
.unwrap();
.set_key_builder(TransparentKeyBuilder::default())
.set_metrics(true)
.finalize()
.unwrap();
c.try_insert_with_ttl(1, 1, 1, ttl).unwrap();
c.wait().unwrap();
let val = c.get(&1).unwrap();
assert!(val.ttl()>Duration::from_millis(900));

assert!(val.ttl() > Duration::from_millis(900));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ pub trait UpdateValidator<V>: Send + Sync + 'static {

/// DefaultUpdateValidator is a noop update validator.
#[doc(hidden)]
pub struct DefaultUpdateValidator<V: Send + Sync> {
pub struct DefaultUpdateValidator<V> {
_marker: PhantomData<fn(V)>,
}

Expand Down Expand Up @@ -501,7 +501,7 @@ pub trait TransparentKey: Hash + Eq {
/// [`DefaultKeyBuilder`]: struct.DefaultKeyBuilder.html
/// [`TransparentKey`]: trait.TransparentKey.html
#[derive(Default, Copy, Clone, Eq, PartialEq, Debug)]
pub struct TransparentKeyBuilder<K: TransparentKey> {
pub struct TransparentKeyBuilder<K> {
_marker: PhantomData<K>,
}

Expand Down
2 changes: 1 addition & 1 deletion src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const DEFAULT_SAMPLES: usize = 5;

macro_rules! impl_policy {
($policy: ident) => {
use crate::policy::DEFAULT_SAMPLES;
use crate::policy::PolicyPair;
use crate::policy::DEFAULT_SAMPLES;

impl $policy {
#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/policy/axync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<S: BuildHasher + Clone + 'static> AsyncLFUPolicy<S> {
}
}

pub(crate) struct PolicyProcessor<S: BuildHasher + Clone + 'static> {
pub(crate) struct PolicyProcessor<S> {
inner: Arc<Mutex<PolicyInner<S>>>,
items_rx: UnboundedReceiver<Vec<u64>>,
stop_rx: Receiver<()>,
Expand Down
2 changes: 1 addition & 1 deletion src/policy/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl<S: BuildHasher + Clone + 'static> LFUPolicy<S> {
}
}

pub(crate) struct PolicyProcessor<S: BuildHasher + Clone + 'static> {
pub(crate) struct PolicyProcessor<S> {
inner: Arc<Mutex<PolicyInner<S>>>,
items_rx: UnboundedReceiver<Vec<u64>>,
stop_rx: Receiver<()>,
Expand Down
7 changes: 1 addition & 6 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,7 @@ impl<V> Debug for StoreItem<V> {

type Shards<V, SS> = Box<[RwLock<HashMap<u64, StoreItem<V>, SS>>; NUM_OF_SHARDS]>;

pub(crate) struct ShardedMap<
V: Send + Sync + 'static,
U = DefaultUpdateValidator<V>,
SS = RandomState,
ES = RandomState,
> {
pub(crate) struct ShardedMap<V, U = DefaultUpdateValidator<V>, SS = RandomState, ES = RandomState> {
shards: Shards<V, SS>,
em: ExpirationMap<ES>,
store_item_size: usize,
Expand Down

0 comments on commit 85c551b

Please sign in to comment.