pub struct Guard<'a, V> { /* private fields */ }Expand description
RAII guard for borrowed values. Holds a read lock on the shard.
Intentionally !Send to prevent holding across .await points,
which could cause deadlocks or excessive lock contention.
For async contexts, use Cache::get_clone() instead.
§Example
ⓘ
// ✅ Good: Guard is dropped before await
let data = {
let guard = cache.get(&key)?;
guard.some_field.clone()
};
some_async_fn(data).await;
// ✅ Good: Use get_clone() for async contexts
let value = cache.get_clone(&key)?;
some_async_fn(&value).await;
// ❌ Bad: Would hold lock across await (won't compile in Send context)
let guard = cache.get(&key)?;
some_async_fn().await;
println!("{:?}", *guard);Trait Implementations§
Source§impl<V: Ord> Ord for Guard<'_, V>
impl<V: Ord> Ord for Guard<'_, V>
Source§impl<V: PartialOrd> PartialOrd for Guard<'_, V>
impl<V: PartialOrd> PartialOrd for Guard<'_, V>
impl<V: Eq> Eq for Guard<'_, V>
impl<V: Sync> Sync for Guard<'_, V>
Auto Trait Implementations§
impl<'a, V> Freeze for Guard<'a, V>
impl<'a, V> !RefUnwindSafe for Guard<'a, V>
impl<'a, V> !Send for Guard<'a, V>
impl<'a, V> Unpin for Guard<'a, V>
impl<'a, V> !UnwindSafe for Guard<'a, 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<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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 more