pub struct Metadata { /* private fields */ }Expand description
Structured metadata attached to crate::AppError.
Internally backed by a sorted inline vector for optimal performance with small field counts. Fields are kept sorted by name for deterministic iteration and O(log n) lookup via binary search.
§Performance
Most errors have 0-4 metadata fields. For these cases, all storage is inline (no heap allocation), saving ~100-200ns per error creation.
Implementations§
Source§impl Metadata
impl Metadata
Sourcepub fn from_fields(fields: impl IntoIterator<Item = Field>) -> Self
pub fn from_fields(fields: impl IntoIterator<Item = Field>) -> Self
Build metadata from an iterator of Field values.
Sourcepub fn insert(&mut self, field: Field) -> Option<FieldValue>
pub fn insert(&mut self, field: Field) -> Option<FieldValue>
Insert or replace a field and return the previous value.
Fields are kept sorted by name for efficient lookup.
Sourcepub fn extend(&mut self, fields: impl IntoIterator<Item = Field>)
pub fn extend(&mut self, fields: impl IntoIterator<Item = Field>)
Extend metadata with additional fields.
Sourcepub fn get(&self, name: &'static str) -> Option<&FieldValue>
pub fn get(&self, name: &'static str) -> Option<&FieldValue>
Borrow a field value by name.
Sourcepub fn get_field(&self, name: &'static str) -> Option<&Field>
pub fn get_field(&self, name: &'static str) -> Option<&Field>
Borrow the full field entry by name.
Sourcepub fn set_redaction(&mut self, name: &'static str, redaction: FieldRedaction)
pub fn set_redaction(&mut self, name: &'static str, redaction: FieldRedaction)
Override the redaction policy for a specific field.
Sourcepub fn redaction(&self, name: &'static str) -> Option<FieldRedaction>
pub fn redaction(&self, name: &'static str) -> Option<FieldRedaction>
Retrieve the redaction policy for a field if present.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&'static str, &FieldValue)>
pub fn iter(&self) -> impl Iterator<Item = (&'static str, &FieldValue)>
Iterator over metadata fields in sorted order.
Sourcepub fn iter_with_redaction(
&self,
) -> impl Iterator<Item = (&'static str, &FieldValue, FieldRedaction)>
pub fn iter_with_redaction( &self, ) -> impl Iterator<Item = (&'static str, &FieldValue, FieldRedaction)>
Iterator over metadata entries including the redaction policy.