Skip to main content

LastErrorSlot

Struct LastErrorSlot 

Source
pub struct LastErrorSlot { /* private fields */ }
Expand description

The last failure recorded on this thread, and its classification.

Place one in a thread_local! in your own crate — see the module docs for why this crate does not own it.

Implementations§

Source§

impl LastErrorSlot

Source

pub const fn new() -> Self

An empty slot: no message, kind kind::NONE.

const so it can be used in thread_local! { static X: _ = const { .. } }, which avoids the lazy-initialisation check on every access.

Source

pub fn set(&self, kind: c_int, message: &str)

Record a failure, replacing whatever was there.

A message holding an interior NUL cannot become a C string; the kind is still recorded and the message is dropped, so the caller gets a classification and a null message rather than a classification paired with the previous message.

Source

pub fn set_error(&self, error: &FfiError)

Record a failure from an FfiError.

Source

pub fn clear(&self)

Forget any recorded failure. Call on entry to an operation that succeeded, so a caller polling the slot does not see an old failure attributed to a new call.

Source

pub fn message_ptr(&self) -> *const c_char

The recorded message as a C string, or null when none is recorded.

§Safety of the returned pointer

Borrowed from thread-local storage: valid until the next call that writes this slot on the same thread. Callers across the ABI must copy it, not retain it. The pointer is produced inside the borrow and no reference escapes, so the value cannot be freed while a caller is still inside the same call.

Source

pub fn kind(&self) -> c_int

The recorded classification, or kind::NONE when the last call succeeded.

Trait Implementations§

Source§

impl Debug for LastErrorSlot

Source§

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

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

impl Default for LastErrorSlot

Source§

fn default() -> Self

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

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.