pub struct Message {
pub message: Cow<'static, str>,
pub class: Option<Class>,
pub values: Metadata,
}Expand description
A diagnostic message with an optional semantic class and named diagnostic values.
Use this instead of chaining message, classification, and scalar-context errors when they describe a single
failure. Self::new() starts without a class or values; Self::with_class() and Self::with() add them.
Class-based constructors such as crate::not_found() combine the message and class in one step.
Unlike ClassificationMarker, this is a visible diagnostic: it participates in
error iteration, downcasting, reports, and cause selection. A marker only adds a classification to an existing
error without a diagnostic of its own, preserving that error’s concrete type. Both are inspected by crate::classify().
The class itself isn’t displayed, and crate::types::Classification::error() refers to this error, not a synthetic source.
Preserve real callee errors with ResultExt::or_raise() or
Exn::raise(). Keep concrete error types when recovery requires their specific payloads;
use classification predicates to recognize categories, and document diagnostic keys on the function returning them.
Exn::metadata() and crate::Error::metadata() yield each message’s non-empty value dictionary.
Dictionaries from separate contexts aren’t merged. To identify a specific failure without inspecting its values,
use Class::Tagged; see matching a specific failure.
Debug formatting omits absent classes and empty values. Present classes omit their Some wrapper,
and the class and values stay on single lines, even in pretty output.
Fields§
§message: Cow<'static, str>The operation or situation described by these values.
class: Option<Class>The semantic class of this diagnostic, if known.
values: MetadataDiagnostic values, ordered by key. Functions returning metadata document their keys.
Implementations§
Source§impl Message
impl Message
Sourcepub fn new(message: impl Into<Cow<'static, str>>) -> Self
pub fn new(message: impl Into<Cow<'static, str>>) -> Self
Create a diagnostic with message, no classification, and no values.
Sourcepub fn with_class(self, class: Class) -> Self
pub fn with_class(self, class: Class) -> Self
Set class, replacing any previous classification without adding a cause.
Sourcepub fn with(
self,
key: impl Into<Cow<'static, str>>,
value: impl Into<MetadataValue>,
) -> Self
pub fn with( self, key: impl Into<Cow<'static, str>>, value: impl Into<MetadataValue>, ) -> Self
Add value under key, replacing any previous value in this context.
Inspect values through crate::Exn::metadata() after raising, or crate::Error::metadata() after wrapping.
Trait Implementations§
Source§impl Error for Message
impl Error for Message
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()