pub struct ShardMap<K, V, const SHARDS: usize = DEFAULT_CACHE_SHARDS> { /* private fields */ }Expand description
Implementations§
Source§impl<K, V, const SHARDS: usize> ShardMap<K, V, SHARDS>
impl<K, V, const SHARDS: usize> ShardMap<K, V, SHARDS>
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty native typed map with an approximate total capacity.
Sourcepub fn with_options(options: ShardMapOptions) -> Self
pub fn with_options(options: ShardMapOptions) -> Self
Creates an empty native typed map with explicit options.
Sourcepub const fn shard_count(&self) -> usize
pub const fn shard_count(&self) -> usize
Returns the configured number of shards.
Sourcepub fn route_key<Q>(&self, key: &Q) -> EmbeddedKeyRoute
pub fn route_key<Q>(&self, key: &Q) -> EmbeddedKeyRoute
Computes the route for a key.
Sourcepub const fn default_ttl_ms(&self) -> Option<u64>
pub const fn default_ttl_ms(&self) -> Option<u64>
Returns the default TTL applied by write APIs that do not pass an explicit TTL.
Sourcepub fn insert(&self, key: K, value: V) -> Option<V>
pub fn insert(&self, key: K, value: V) -> Option<V>
Inserts or replaces a value, returning the old value when present.
Sourcepub fn insert_with_ttl(
&self,
key: K,
value: V,
ttl_ms: Option<u64>,
) -> Option<V>
pub fn insert_with_ttl( &self, key: K, value: V, ttl_ms: Option<u64>, ) -> Option<V>
Inserts or replaces a value with an optional relative TTL, returning the old live value when present.
Sourcepub fn try_insert(&self, key: K, value: V) -> bool
pub fn try_insert(&self, key: K, value: V) -> bool
Inserts only when the key is absent.
Sourcepub fn try_insert_with_ttl(&self, key: K, value: V, ttl_ms: Option<u64>) -> bool
pub fn try_insert_with_ttl(&self, key: K, value: V, ttl_ms: Option<u64>) -> bool
Inserts only when the key is absent or expired, with an optional relative TTL.
Sourcepub fn get_ref<Q>(&self, key: &Q) -> Option<ShardMapRef<'_, K, V>>
pub fn get_ref<Q>(&self, key: &Q) -> Option<ShardMapRef<'_, K, V>>
Returns a borrowed value guard.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true when the key is present.
Sourcepub fn remove<Q>(&self, key: &Q) -> Option<V>
pub fn remove<Q>(&self, key: &Q) -> Option<V>
Removes a key and returns its value when present.
Sourcepub fn visit_keys(&self, visitor: impl FnMut(&K) -> bool)
pub fn visit_keys(&self, visitor: impl FnMut(&K) -> bool)
Visits keys without allocating a snapshot.
The visitor runs while each shard read lock is held. Keep callbacks
lightweight, and return false to stop early.