pub trait Emit {
// Required method
fn emit(&self) -> DiagnosticEmitted;
}Expand description
Trait for types that can emit themselves as diagnostics.
Even in the error handling framework set up in formally, in some cases the best design for a
function is to return a classic Result<T, E> for some specific error type E and postpone the
emission of diagnostics. In this case one can embedd in the error type all the necessary
information to generate the diagnostics later, and implement Emit for the error type.
Then, the error type can be used as any other, but in addition, DiagnosticEmitted implements
From<E> for any E that implement Emit, and the conversion emits the diagnostics. This
means that one can very conveniently apply to E the ? operator in a function returning
Result<T, DiagnosticEmitted>, if and when one desires to finally emit the diagnostics.
A suggested way to declare error types is using the thiserror crate. In this case, to inherit
a sensible implementation of Emit for common error types one can implement Diagnosable
instead. For an example see formally::smt::backends::BackendError type, and the documentation
of Diagnosable.
Required Methods§
Sourcefn emit(&self) -> DiagnosticEmitted
fn emit(&self) -> DiagnosticEmitted
Emit the object as a diagnostic.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".