use std::hash::Hash;
use super::Storage;
pub(crate) struct EngineWideStorage<Key, Value, LockingPolicy>
where
LockingPolicy: super::LockingPolicy,
{
inner: Storage<Key, Value, LockingPolicy>,
}
impl<Key, Value, LockingPolicy> EngineWideStorage<Key, Value, LockingPolicy>
where
LockingPolicy: super::LockingPolicy,
{
pub(super) fn new(inner: Storage<Key, Value, LockingPolicy>) -> Self {
Self { inner }
}
pub(crate) fn is_empty(&self) -> bool {
self.inner.is_empty()
}
}
impl<Key, Value, LockingPolicy> EngineWideStorage<Key, Value, LockingPolicy>
where
Key: Hash + Eq,
LockingPolicy: super::LockingPolicy,
{
pub(crate) fn with<Reader, Output>(&self, key: &Key, reader: Reader) -> Option<Output>
where
Reader: FnOnce(&Value) -> Output,
{
self.inner.with(key, reader)
}
pub(crate) fn insert_if_absent<Initializer>(&self, key: Key, default: Initializer) -> bool
where
Initializer: FnOnce() -> Value,
{
self.inner.insert_if_absent(key, default)
}
pub(crate) fn upsert<Mutator, Output, Initializer>(
&self,
key: Key,
default: Initializer,
mutator: Mutator,
) -> Output
where
Mutator: FnOnce(&mut Value, bool) -> Output,
Initializer: FnOnce() -> Value,
Key: Clone,
{
self.inner.with_mut_exclusive_index(key, default, mutator)
}
pub(crate) fn with_mut_if_present<Mutator, Output>(
&self,
key: &Key,
mutator: Mutator,
) -> Option<Output>
where
Mutator: FnOnce(&mut Value) -> Output,
{
self.inner.with_mut_if_present_exclusive_index(key, mutator)
}
pub(crate) fn remove(&self, key: &Key) -> bool {
self.inner.remove(key)
}
}