pub trait PerBufferCacheExt<T> {
// Required methods
fn get_for(&self, id: BufferId) -> Option<Arc<T>>;
fn insert_for(&self, id: BufferId, value: T);
fn remove_for(&self, id: BufferId);
fn retain<F: FnMut(BufferId, &T) -> bool>(&self, predicate: F);
fn is_empty_snapshot(&self) -> bool;
}Expand description
Convenience trait carrying the standard read / insert /
remove operations for a PerBufferCache.
All operations are non-blocking. Writes use a copy-on-write
pattern: load the current Arc<HashMap>, clone the inner
HashMap, mutate, store. Concurrent writers may race; the
last-writer-wins outcome is acceptable for LSP feature caches
(each buffer’s writer is itself single-flight via
cancellation tokens; cross-buffer races are independent).
Required Methods§
Sourcefn get_for(&self, id: BufferId) -> Option<Arc<T>>
fn get_for(&self, id: BufferId) -> Option<Arc<T>>
Wait-free read: returns a detached Arc<T> snapshot of
the cache entry for id, or None if no entry exists.
The returned Arc is independent of any subsequent
store; the renderer can hold it across the frame.
Sourcefn insert_for(&self, id: BufferId, value: T)
fn insert_for(&self, id: BufferId, value: T)
Store (or replace) the cache entry for id. Copy-on-
write: clones the current HashMap, inserts, stores.
Sourcefn remove_for(&self, id: BufferId)
fn remove_for(&self, id: BufferId)
Remove the cache entry for id if present. No-op when
the entry doesn’t exist. Copy-on-write semantics.
Sourcefn retain<F: FnMut(BufferId, &T) -> bool>(&self, predicate: F)
fn retain<F: FnMut(BufferId, &T) -> bool>(&self, predicate: F)
Retain only entries matching the predicate. Mirrors
HashMap::retain’s semantics: the predicate sees each
(BufferId, &T); entries returning false are dropped.
Copy-on-write: if no entries need to be dropped, the
underlying Arc is unchanged. Used by LSP */refresh
drains to evict per-server caches when a server’s
invalidation notification arrives.
Sourcefn is_empty_snapshot(&self) -> bool
fn is_empty_snapshot(&self) -> bool
Returns true when no entries exist. Wait-free.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".