pub struct Metadata(/* private fields */);Expand description
An ordered dictionary of named diagnostic values belonging to a single error context.
Functions returning metadata document the keys and their meaning. crate::Exn::metadata() and
crate::Error::metadata() yield non-empty dictionaries separately; dictionaries from independent causes
are never merged. Keys are iterated and formatted in lexicographic order.
Debug formatting and Message’s display omit key quotes for non-empty names containing only ASCII
letters, digits, _, -, or .. Other keys use quoted, escaped string formatting.
§Common schemas
These schemas define conventional keys, not required fields. Store only information already available at the failure site; do not collect additional information just to populate a schema. Omitted keys mean the information was not recorded, not that it was empty or absent. Functions returning metadata document which keys they provide. Metadata alone does not establish a semantic classification or whether recovery is safe.
§Input validation
| Key | Value | Meaning |
|---|---|---|
input | Any MetadataValue | The offending input, preserving its original representation where possible. |
Use Message::with_input() to record already-known input. This convention also applies to malformed data
classified as Class::Corruption; attaching input does not imply Class::Validation. Do not record secrets
or other sensitive input that should not appear in diagnostics.
§External program runtime failure
| Key | Value | Meaning |
|---|---|---|
program | MetadataValue::Path | The invoked program name or path, without resolving it. |
exit_status | MetadataValue::String | The display representation of std::process::ExitStatus, including termination without an exit code. |
exit_code | MetadataValue::I64 | The exit code, when std::process::ExitStatus::code() returns one. |
stdout | MetadataValue::Bytes | Captured standard output, without text decoding. |
stderr | MetadataValue::Bytes | Captured standard error, without text decoding. |
Use Message::with_command_status() to record program, exit_status, and an available exit_code together,
or Message::with_command_output() to include already-captured output. Message::with_program() and
Message::with_exit_status() record the fields available at spawn failures or after program identity was lost.
A failed exit status does not by itself establish a recovery class. Preserve native errors from spawning or
communicating with a program as causes; their contexts can also use program, without an exit status or output.
Implementations§
Source§impl Metadata
impl Metadata
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Return whether a value is recorded under key.
Sourcepub fn get(&self, key: &str) -> Option<&MetadataValue>
pub fn get(&self, key: &str) -> Option<&MetadataValue>
Return the value recorded under key, if present.
Sourcepub fn get_mut(&mut self, key: &str) -> Option<&mut MetadataValue>
pub fn get_mut(&mut self, key: &str) -> Option<&mut MetadataValue>
Return a mutable reference to the value recorded under key, if present.
Sourcepub fn insert(
&mut self,
key: impl Into<Cow<'static, str>>,
value: impl Into<MetadataValue>,
) -> Option<MetadataValue>
pub fn insert( &mut self, key: impl Into<Cow<'static, str>>, value: impl Into<MetadataValue>, ) -> Option<MetadataValue>
Record value under key, returning any previous value.
Sourcepub fn remove(&mut self, key: &str) -> Option<MetadataValue>
pub fn remove(&mut self, key: &str) -> Option<MetadataValue>
Remove and return the value recorded under key, if present.
Sourcepub fn iter(
&self,
) -> impl DoubleEndedIterator<Item = (&Cow<'static, str>, &MetadataValue)> + ExactSizeIterator + '_
pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = (&Cow<'static, str>, &MetadataValue)> + ExactSizeIterator + '_
Iterate over keys and values in lexicographic key order.
Sourcepub fn iter_mut(
&mut self,
) -> impl DoubleEndedIterator<Item = (&Cow<'static, str>, &mut MetadataValue)> + ExactSizeIterator + '_
pub fn iter_mut( &mut self, ) -> impl DoubleEndedIterator<Item = (&Cow<'static, str>, &mut MetadataValue)> + ExactSizeIterator + '_
Iterate over keys and mutable values in lexicographic key order.
Trait Implementations§
Source§impl Extend<(Cow<'static, str>, MetadataValue)> for Metadata
impl Extend<(Cow<'static, str>, MetadataValue)> for Metadata
Source§fn extend<T: IntoIterator<Item = (Cow<'static, str>, MetadataValue)>>(
&mut self,
iter: T,
)
fn extend<T: IntoIterator<Item = (Cow<'static, str>, MetadataValue)>>( &mut self, iter: T, )
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)