pub trait Emitter {
// Required methods
fn emit(&self, level: Level, diag: Diagnostic);
fn note(&self, kind: NoteKind, note: Diagnostic);
}Expand description
Trait for objects capable of emitting (or routing) diagnostics.
Emitter is the core of formally’s error handling strategy. Diagnostics, in the form of
Diagnostic objects, are just messages sent to the user possibly associated with a source span.
Emitters can potentially do whatever they wish with a diagnostic, including rendering them to
the user, ignoring them, delaying them (as with BatchEmitter), or relaying them to other
emitters, possibly after some processing.
The emission of a diagnostic can be followed by one or more notes that allow to specify additional information associated with different source spans.
For consistency of the user experience, it is important that everybody uses the same Emitter. For this reason, a global Emitter is always available from Diagnostic::emitter(), which returns a global emitter object whose default value can be changed with Diagnostic::set_default_global_emitter(). The global emitter can be temporarily changed in a thread-local and scoped way with Diagnostic::with().
Different implementations of Emitter are provided and more will be added. Currently, we have:
- StdErrEmitter, to direct formatted messages to the standard error stream. This is currently the default global emitter.
- BatchEmitter, to group diagnostics and emitting them all at once when requested
- NullEmitter, to suppress any diagnostic.
Diagnostic objects are usually not constructed and emitted directly but using the debug, warning and error macros. Similarly, notes are usually emitted with the note and trace macros. These macros use the global Emitter.
Example:
error!(span, "unable to parse identifier: {}", ident);Required Methods§
Sourcefn emit(&self, level: Level, diag: Diagnostic)
fn emit(&self, level: Level, diag: Diagnostic)
Emit a diagnostic.
Sourcefn note(&self, kind: NoteKind, note: Diagnostic)
fn note(&self, kind: NoteKind, note: Diagnostic)
Emit a note.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".