pub struct Attrs { /* private fields */ }
Expand description
A heterogeneous, strongly-typed attribute dictionary with serialization support.
This dictionary stores key-value pairs where:
- Keys are type-safe and must be predefined with their associated types
- Values must implement
Send + Sync + Serialize + DeserializeOwned + Named + 'static
- The entire dictionary can be serialized to/from JSON automatically
§Type Safety
The dictionary enforces type safety at compile time. You cannot retrieve a value with the wrong type, and the compiler will catch such errors.
§Serialization
The dictionary can be serialized using serde. During serialization, each value is serialized with its key name. During deserialization, the automatically registered key information is used to determine the correct type for each value.
Implementations§
Source§impl Attrs
impl Attrs
Sourcepub fn set<T: Send + Sync + Serialize + DeserializeOwned + Named + Clone + 'static>(
&mut self,
key: Key<T>,
value: T,
)
pub fn set<T: Send + Sync + Serialize + DeserializeOwned + Named + Clone + 'static>( &mut self, key: Key<T>, value: T, )
Set a value for the given key.
Sourcepub fn get<T: Send + Sync + Serialize + DeserializeOwned + Named + 'static>(
&self,
key: Key<T>,
) -> Option<&T>
pub fn get<T: Send + Sync + Serialize + DeserializeOwned + Named + 'static>( &self, key: Key<T>, ) -> Option<&T>
Get a value for the given key, returning None if not present. If the key has a default value, that is returned instead.
Sourcepub fn get_mut<T: Send + Sync + Serialize + DeserializeOwned + Named + Clone + 'static>(
&mut self,
key: Key<T>,
) -> Option<&mut T>
pub fn get_mut<T: Send + Sync + Serialize + DeserializeOwned + Named + Clone + 'static>( &mut self, key: Key<T>, ) -> Option<&mut T>
Get a mutable reference to a value for the given key. If the key has a default value, it is first set, and then returned as a mutable reference.
Sourcepub fn remove<T: Send + Sync + Serialize + DeserializeOwned + Named + 'static>(
&mut self,
key: Key<T>,
) -> bool
pub fn remove<T: Send + Sync + Serialize + DeserializeOwned + Named + 'static>( &mut self, key: Key<T>, ) -> bool
Remove a value for the given key, returning it if present.
Sourcepub fn contains_key<T: Send + Sync + Serialize + DeserializeOwned + Named + 'static>(
&self,
key: Key<T>,
) -> bool
pub fn contains_key<T: Send + Sync + Serialize + DeserializeOwned + Named + 'static>( &self, key: Key<T>, ) -> bool
Checks if the given key exists in the dictionary.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Attrs
impl<'de> Deserialize<'de> for Attrs
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<T: Send + Sync + Serialize + DeserializeOwned + Named + 'static> Index<Key<T>> for Attrs
impl<T: Send + Sync + Serialize + DeserializeOwned + Named + 'static> Index<Key<T>> for Attrs
Auto Trait Implementations§
impl Freeze for Attrs
impl !RefUnwindSafe for Attrs
impl Send for Attrs
impl Sync for Attrs
impl Unpin for Attrs
impl !UnwindSafe for Attrs
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<A, M> Handler<IndexedErasedUnbound<M>> for A
impl<A, M> Handler<IndexedErasedUnbound<M>> for A
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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