pub struct ErrorMetadata { /* private fields */ }Expand description
Typed structured metadata attached to an error context.
Unlike OperationContext::with_field
and OperationContext::record, whose
entries appear in the error’s Display output, metadata stored here is not visible in
terminal output. It is intended for programmatic consumers: serialization,
snapshots, structured logs, and API responses.
Supports String, bool, i64, and u64 values via MetadataValue.
Implementations§
Source§impl ErrorMetadata
impl ErrorMetadata
Sourcepub fn as_map(&self) -> &BTreeMap<String, MetadataValue>
pub fn as_map(&self) -> &BTreeMap<String, MetadataValue>
Borrow the underlying map for read-only access.
Sourcepub fn insert<K, V>(&mut self, key: K, value: V)
pub fn insert<K, V>(&mut self, key: K, value: V)
Insert a key-value pair into the metadata.
Supports any key type that converts into String and any value
type that converts into MetadataValue (i.e. String, bool,
i64, u64, and their subtypes).
Sourcepub fn get(&self, key: &str) -> Option<&MetadataValue>
pub fn get(&self, key: &str) -> Option<&MetadataValue>
Look up a key and return its typed value.
Sourcepub fn get_str(&self, key: &str) -> Option<&str>
pub fn get_str(&self, key: &str) -> Option<&str>
Look up a key and return its &str value, or None if the key
is absent or the value is not a string variant.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&String, &MetadataValue)>
pub fn iter(&self) -> impl Iterator<Item = (&String, &MetadataValue)>
Iterate over all key-value pairs.
Sourcepub fn merge_missing(&mut self, other: &ErrorMetadata)
pub fn merge_missing(&mut self, other: &ErrorMetadata)
Merge entries from other, keeping existing values.
For each key in other, the value is only inserted if the key does not
already exist in self. This implements an inner/first wins strategy
useful when merging layered metadata where earlier layers should take
priority.
See StructError::context_metadata()
for a usage example.
Trait Implementations§
Source§impl Clone for ErrorMetadata
impl Clone for ErrorMetadata
Source§fn clone(&self) -> ErrorMetadata
fn clone(&self) -> ErrorMetadata
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more