pub trait ErrorReport {
// Required method
fn message(&self) -> String;
// Provided methods
fn code(&self) -> i32 { ... }
fn payload(&self) -> Vec<u8> ⓘ { ... }
}Expand description
Maps a producer error onto the ABI’s (code, message, payload) triple.
A fallible #[weaveffi::export] function returning Result<T, E> reports
Err(e) through its trailing out_err slot using this trait. String and
&str errors are covered out of the box with the generic code -1, so
Result<T, String> needs no extra code. The #[weaveffi::error]
expansion implements it for an error domain’s enum: the code is the
variant’s discriminant, the message is the enum’s
Display output, and the payload is the variant’s
fields.
To implement the trait by hand:
use weaveffi::abi::ErrorReport;
enum KvError {
KeyNotFound,
Io(String),
}
impl ErrorReport for KvError {
fn code(&self) -> i32 {
match self {
KvError::KeyNotFound => 1001,
KvError::Io(_) => 1004,
}
}
fn message(&self) -> String {
match self {
KvError::KeyNotFound => "key not found".to_string(),
KvError::Io(detail) => format!("I/O error: {detail}"),
}
}
}Required Methods§
Sourcefn message(&self) -> String
fn message(&self) -> String
The human-readable message written to FfiError::message.
Provided Methods§
Sourcefn code(&self) -> i32
fn code(&self) -> i32
The non-zero status code written to FfiError::code. Defaults to
GENERIC_ERROR_CODE.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Implementors§
impl ErrorReport for ForeignError
A ForeignError is reported with its own code, message, and payload, so
a producer function whose error type is ForeignError can propagate a
callback failure with ?.