pub struct Metadata<E: Context, K: Span, V: Codec>(/* private fields */);Expand description
Implementation of Metadata storage.
Storage-mutating functions consume the store and return it only on success: an error (or a dropped future) destroys the handle.
Implementations§
Source§impl<E: Context, K: Span, V: Codec> Metadata<E, K, V>
impl<E: Context, K: Span, V: Codec> Metadata<E, K, V>
Sourcepub async fn init(context: E, cfg: Config<V::Cfg>) -> Result<Self, Error>
pub async fn init(context: E, cfg: Config<V::Cfg>) -> Result<Self, Error>
Initialize a new Metadata instance.
Sourcepub fn get_mut(&mut self, key: &K) -> Option<&mut V>
pub fn get_mut(&mut self, key: &K) -> Option<&mut V>
Get a mutable reference to a value from Metadata (if it exists).
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear all values from Metadata. The new state will not be persisted until Self::sync is called.
Sourcepub fn put(&mut self, key: K, value: V) -> Option<V>
pub fn put(&mut self, key: K, value: V) -> Option<V>
Put a value into Metadata.
If the key already exists, the value will be overwritten and the previous value is returned. The value stored will not be persisted until Self::sync is called.
Sourcepub async fn put_sync(self, key: K, value: V) -> Result<Self, Error>
pub async fn put_sync(self, key: K, value: V) -> Result<Self, Error>
Perform a Self::put and Self::sync in a single operation.
Like calling Self::sync directly, this commits all pending metadata changes, not just the provided key.
Sourcepub fn upsert(&mut self, key: K, f: impl FnOnce(&mut V))where
V: Default,
pub fn upsert(&mut self, key: K, f: impl FnOnce(&mut V))where
V: Default,
Update (or insert) a value in Metadata using a closure.
Sourcepub async fn upsert_sync(
self,
key: K,
f: impl FnOnce(&mut V),
) -> Result<Self, Error>where
V: Default,
pub async fn upsert_sync(
self,
key: K,
f: impl FnOnce(&mut V),
) -> Result<Self, Error>where
V: Default,
Update (or insert) a value in Metadata using a closure and sync immediately.
Sourcepub fn retain(&mut self, f: impl FnMut(&K, &V) -> bool)
pub fn retain(&mut self, f: impl FnMut(&K, &V) -> bool)
Retain only the keys that satisfy the predicate.
Sourcepub async fn sync(self) -> Result<Self, Error>
pub async fn sync(self) -> Result<Self, Error>
Atomically commit the current state of Metadata.
Sourcepub async fn start_sync(self) -> Result<(Self, Handle<()>), Error>
pub async fn start_sync(self) -> Result<(Self, Handle<()>), Error>
Atomically begin committing the current state of Metadata, returning a completion handle.
Awaiting the returned Handle provides the same guarantee as Self::sync. A started sync’s failure surfaces on the handle and again on the next sync, which fails (destroying the store) without writing. At most one sync is in flight: a new call writes nothing until the prior sync completes. Dropping the handle neither cancels the sync nor loses a failure.
Trait Implementations§
Auto Trait Implementations§
impl<E, K, V> !RefUnwindSafe for Metadata<E, K, V>
impl<E, K, V> !UnwindSafe for Metadata<E, K, V>
impl<E, K, V> Freeze for Metadata<E, K, V>
impl<E, K, V> Send for Metadata<E, K, V>
impl<E, K, V> Sync for Metadata<E, K, V>
impl<E, K, V> Unpin for Metadata<E, K, V>
impl<E, K, V> UnsafeUnpin for Metadata<E, K, V>where
Box<Inner<E, K, V>>: UnsafeUnpin,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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> ⓘ
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> ⓘ
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