Skip to main content

Metadata

Struct Metadata 

Source
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

KeyValueMeaning
inputAny MetadataValueThe 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

KeyValueMeaning
programMetadataValue::PathThe invoked program name or path, without resolving it.
exit_statusMetadataValue::StringThe display representation of std::process::ExitStatus, including termination without an exit code.
exit_codeMetadataValue::I64The exit code, when std::process::ExitStatus::code() returns one.
stdoutMetadataValue::BytesCaptured standard output, without text decoding.
stderrMetadataValue::BytesCaptured 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

Source

pub fn new() -> Self

Create an empty dictionary.

Source

pub fn len(&self) -> usize

Return the number of values in this dictionary.

Source

pub fn is_empty(&self) -> bool

Return whether this dictionary has no values.

Source

pub fn contains_key(&self, key: &str) -> bool

Return whether a value is recorded under key.

Source

pub fn get(&self, key: &str) -> Option<&MetadataValue>

Return the value recorded under key, if present.

Source

pub fn get_mut(&mut self, key: &str) -> Option<&mut MetadataValue>

Return a mutable reference to the value recorded under key, if present.

Source

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.

Source

pub fn remove(&mut self, key: &str) -> Option<MetadataValue>

Remove and return the value recorded under key, if present.

Source

pub fn clear(&mut self)

Remove all recorded values.

Source

pub fn iter( &self, ) -> impl DoubleEndedIterator<Item = (&Cow<'static, str>, &MetadataValue)> + ExactSizeIterator + '_

Iterate over keys and values in lexicographic key order.

Source

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 Clone for Metadata

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Metadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Metadata

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Extend<(Cow<'static, str>, MetadataValue)> for Metadata

Source§

fn extend<T: IntoIterator<Item = (Cow<'static, str>, MetadataValue)>>( &mut self, iter: T, )

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<const N: usize> From<[(Cow<'static, str>, MetadataValue); N]> for Metadata

Source§

fn from(values: [(Cow<'static, str>, MetadataValue); N]) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<(Cow<'static, str>, MetadataValue)> for Metadata

Source§

fn from_iter<T: IntoIterator<Item = (Cow<'static, str>, MetadataValue)>>( iter: T, ) -> Self

Creates a value from an iterator. Read more
Source§

impl Index<&str> for Metadata

Source§

type Output = MetadataValue

The returned type after indexing.
Source§

fn index(&self, key: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl PartialEq for Metadata

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Metadata

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.