Skip to main content

Message

Trait Message 

Source
pub trait Message: MessageBehaviour {
    // Required methods
    fn as_any(&self) -> &dyn Any;
    fn level(&self) -> Level;
    fn msg(&self) -> &'static str;
    fn origin(&self) -> &'static Origin;

    // Provided methods
    fn as_facet(&self) -> Option<Peek<'_, 'static>> { ... }
    fn as_serialize(&self) -> Option<&dyn Serialize> { ... }
    fn tags(&self) -> &'static [&'static str] { ... }
}
Expand description

A struct that may be emitted as a wide event.

Apply #[message], which implements this trait, enforces that every field is a Field, and fills the inherent consts (MSG, LEVEL, ORIGIN, TAGS) the methods below mirror (associated consts aren’t object-safe).

Object-safe, so subscribers can receive &dyn Message. Pseudo-sealed against accidental hand-written impls via the hidden [__private::MessageBehaviour] supertrait, which only #[message] emits — see [__private::Sealed] for why it’s only a pseudo-seal.

Required Methods§

Source

fn as_any(&self) -> &dyn Any

Escape hatch for subscribers that want the concrete type back, via as_any().downcast_ref::<T>().

Source

fn level(&self) -> Level

Severity of this event type; #[message(level = ...)], default INFO.

Source

fn msg(&self) -> &'static str

The constant, static message text.

Source

fn origin(&self) -> &'static Origin

Where this message type is defined — automatic provenance, never set by hand. See Origin.

Provided Methods§

Source

fn as_facet(&self) -> Option<Peek<'_, 'static>>

Erased reflection hook, keyed on one knob: #[derive(Facet)].

Via [__private::facet] autoref specialization the generated body returns Some (a Peek over self) when the type derives Facet and None otherwise — no Facet bound ever lands on a message that didn’t derive it. The introspection parallel to as_serialize: a subscriber walks the Peek to read fields by name and filter on a field’s value, which static tags cannot.

Source

fn as_serialize(&self) -> Option<&dyn Serialize>

Erased serialization hook, keyed on one knob: #[derive(Serialize)].

Via [__private::serde] autoref specialization the generated body returns Some(self) when the type derives Serialize and None otherwise — no Serialize bound ever lands on a message that didn’t derive it. The only serde surface in the core; dyn erased_serde::Serialize implements serde::Serialize, so a subscriber serializes the result with any format.

Source

fn tags(&self) -> &'static [&'static str]

Static routing tags: the sorted, deduped, lowercased set from #[message(tags = [...])], default empty. Where origin is provenance (where defined), tags are intent (where to send) — routing is the subscriber’s call, e.g. m.tags().contains(&"analytics").

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§