pub struct BufferRing<K, V>{ /* private fields */ }Expand description
Fixed-capacity circular cache.
Inserting into a full ring evicts the slot at the current hand
position and returns the evicted (key, value) so the caller can
flush it (e.g. through the pager’s double-write buffer for
BulkWrite strategies).
Implementations§
Source§impl<K, V> BufferRing<K, V>
impl<K, V> BufferRing<K, V>
Sourcepub fn new(capacity: usize) -> Self
pub fn new(capacity: usize) -> Self
Create a new ring with the given fixed capacity. capacity is
clamped to at least 1.
Sourcepub fn get(&self, key: &K) -> Option<V>
pub fn get(&self, key: &K) -> Option<V>
Look up a key. Does NOT update any recency / visited state.
Sourcepub fn insert(&self, key: K, value: V) -> Option<(K, V)>
pub fn insert(&self, key: K, value: V) -> Option<(K, V)>
Insert a (key, value) pair. If the ring is full, the slot at
the current hand position is evicted and the hand advances.
Returns the evicted (key, value) if any.
If key is already present in the ring, its slot is updated in
place and None is returned.
Auto Trait Implementations§
impl<K, V> !Freeze for BufferRing<K, V>
impl<K, V> RefUnwindSafe for BufferRing<K, V>
impl<K, V> Send for BufferRing<K, V>
impl<K, V> Sync for BufferRing<K, V>
impl<K, V> Unpin for BufferRing<K, V>
impl<K, V> UnsafeUnpin for BufferRing<K, V>
impl<K, V> UnwindSafe for BufferRing<K, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request