Skip to main content

FfiError

Struct FfiError 

Source
#[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: i32

Status 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_char

Owned, NUL-terminated UTF-8 message describing the failure, or null when code is 0.

§payload_ptr: *const u8

Owned value buffer holding the matched error code’s payload fields, or null when the code declares no fields.

§payload_len: usize

Byte length of payload_ptr; 0 when null.

Implementations§

Source§

impl FfiError

Source

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.

Source

pub fn from_report<E: ErrorReport + ?Sized>(e: &E) -> Self

Build the error an ErrorReport value describes, including its serialized payload.

Source

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.

Source

pub fn cancelled() -> Self

The error a cancelled async call completes with.

Source

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.

Source

pub fn payload(&self) -> &[u8] ⓘ

The payload as a byte slice (empty when there is none).

Trait Implementations§

Source§

impl Debug for FfiError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FfiError

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for FfiError

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for FfiError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.