#[repr(C)]pub struct FfiError {
pub code: i32,
pub message: *const c_char,
pub payload_ptr: *const u8,
pub payload_len: usize,
}Expand description
The error struct passed across the C ABI boundary ({prefix}_error in C).
code == 0 means success and every pointer is null. Otherwise message
is a NUL-terminated UTF-8 string and payload_ptr/payload_len
optionally hold the matched error code’s fields serialized in the
buffer format. The producer allocates both, and
error_clear (the body of {prefix}_error_clear) frees them.
The struct owns its allocations, so it must not be copied bitwise while it holds any; a copy would double-free on clear.
Fields§
§code: i32Status code. 0 means success; a positive value is a domain error
code and a negative value is one of the reserved runtime codes.
message: *const c_charOwned, NUL-terminated UTF-8 message describing the failure, or null
when code is 0.
payload_ptr: *const u8Owned value buffer holding the matched error code’s payload fields, or null when the code declares no fields.
payload_len: usizeByte length of payload_ptr; 0 when null.
Implementations§
Source§impl FfiError
impl FfiError
Sourcepub fn new(code: i32, message: &str) -> Self
pub fn new(code: i32, message: &str) -> Self
Build an owned error with code and message. Interior NUL bytes are
dropped from the message, since C reads it as a NUL-terminated string.
Sourcepub fn from_report<E: ErrorReport + ?Sized>(e: &E) -> Self
pub fn from_report<E: ErrorReport + ?Sized>(e: &E) -> Self
Build the error an ErrorReport value describes, including its
serialized payload.
Sourcepub fn from_panic(payload: &(dyn Any + Send)) -> Self
pub fn from_panic(payload: &(dyn Any + Send)) -> Self
Build the error a caught unwind payload describes: a producer panic,
reported with PANIC_ERROR_CODE.
Sourcepub unsafe fn message_str(&self) -> Option<&str>
pub unsafe fn message_str(&self) -> Option<&str>
The message as a string slice, or None when it’s null or not UTF-8.
§Safety
message must be null or point to a NUL-terminated string that stays
valid for the borrow, which holds for any error this runtime filled.