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
impl LastErrorSlot
Sourcepub const fn new() -> Self
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.
Sourcepub fn set(&self, kind: c_int, message: &str)
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.
Sourcepub fn clear(&self)
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.
Sourcepub fn message_ptr(&self) -> *const c_char
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.
Sourcepub fn kind(&self) -> c_int
pub fn kind(&self) -> c_int
The recorded classification, or kind::NONE when the last call succeeded.