pub trait Report {
// Provided methods
fn report_user_error(err: &Error) -> Result<()> { ... }
fn report_error<T>(err: &ParolError, file_name: T) -> Result<()>
where T: AsRef<Path> { ... }
}Expand description
Trait for parol’s error reporting
Implement this trait and provide an own implementation for Report::report_user_error when you want to contribute your own error reporting for your error types.
If you don’t want to report own errors then simply use it’s default implementation like this:
use parol_runtime::Report;
use parol_macros::parol;
struct MyErrorReporter;
impl Report for MyErrorReporter {
#[cfg(not(feature = "reporting"))]
fn report_user_error(err: &anyhow::Error) -> anyhow::Result<()> { Ok(()) }
#[cfg(not(feature = "reporting"))]
fn report_error<T>(err: &parol_runtime::ParolError, file_name: T) -> anyhow::Result<()>
where T: AsRef<std::path::Path>
{ Ok(()) }
};
let err = parol!("Crucial problem!"); // Suppose that this error comes from a call of `parse`
MyErrorReporter::report_error(&err, "my_file.xyz").unwrap_or_default();Provided Methods§
Sourcefn report_user_error(err: &Error) -> Result<()>
fn report_user_error(err: &Error) -> Result<()>
Implement this method if you want to provide your own error reporting for your own error types. Doing so you can hook into the error reporting process.
Examples are parol’s ParolErrorReporter or basic_interpreter’s BasicErrorReporter.
The method’s argument value is obtained from a parol_runtime::ParolError::UserError’s
content. It should return Ok(()) if reporting succeeds and an error value if the reporting
itself fails somehow.
Sourcefn report_error<T>(err: &ParolError, file_name: T) -> Result<()>
fn report_error<T>(err: &ParolError, file_name: T) -> Result<()>
You don’t need to implement this method because it contains the reporting functionality for errors from parol_runtime itself.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.