Struct rune_native::Error
source · [−]pub struct Error(_);
Expand description
An error that may be returned by the Rune native library.
Error Handling
Fallible functions will return a *mut Error
which must be checked before
continuing.
This might look like…
Runtime *runtime;
Config cfg = {...};
Error *error = rune_runtime_load(&cfg, &runtime);
if (error) {
const char *msg = rune_error_to_string(error);
printf("Unable to load the Rune: %s\n", msg);
free(msg);
rune_error_free(error);
exit(1);
}
Additional “return” values are returned via output parameters (typically
named xxx_out
). If an error occurs, the state of the output parameter is
unspecified, otherwise it is guaranteed to be in a valid state.
If an error is present, it is the caller’s responsibility to free it afterwards.
Implementations
Methods from Deref<Target = Error>
sourcepub fn backtrace(&self) -> &Backtrace
pub fn backtrace(&self) -> &Backtrace
Get the backtrace for this Error.
In order for the backtrace to be meaningful, one of the two environment
variables RUST_LIB_BACKTRACE=1
or RUST_BACKTRACE=1
must be defined
and RUST_LIB_BACKTRACE
must not be 0
. Backtraces are somewhat
expensive to capture in Rust, so we don’t necessarily want to be
capturing them all over the place all the time.
- If you want panics and errors to both have backtraces, set
RUST_BACKTRACE=1
; - If you want only errors to have backtraces, set
RUST_LIB_BACKTRACE=1
; - If you want only panics to have backtraces, set
RUST_BACKTRACE=1
andRUST_LIB_BACKTRACE=0
.
Stability
Standard library backtraces are only available on the nightly channel. Tracking issue: rust-lang/rust#53487.
On stable compilers, this function is only available if the crate’s
“backtrace” feature is enabled, and will use the backtrace
crate as
the underlying backtrace implementation.
[dependencies]
anyhow = { version = "1.0", features = ["backtrace"] }
sourcepub fn chain(&self) -> Chain<'_>
pub fn chain(&self) -> Chain<'_>
An iterator of the chain of source errors contained by this Error.
This iterator will visit every error in the cause chain of this error object, beginning with the error that this error object was created from.
Example
use anyhow::Error;
use std::io;
pub fn underlying_io_error_kind(error: &Error) -> Option<io::ErrorKind> {
for cause in error.chain() {
if let Some(io_error) = cause.downcast_ref::<io::Error>() {
return Some(io_error.kind());
}
}
None
}
sourcepub fn root_cause(&self) -> &(dyn Error + 'static)
pub fn root_cause(&self) -> &(dyn Error + 'static)
The lowest level cause of this error — this error’s cause’s cause’s cause etc.
The root cause is the last error in the iterator produced by
chain()
.
sourcepub fn is<E>(&self) -> bool where
E: 'static + Display + Debug + Send + Sync,
pub fn is<E>(&self) -> bool where
E: 'static + Display + Debug + Send + Sync,
Returns true if E
is the type held by this error object.
For errors with context, this method returns true if E
matches the
type of the context C
or the type of the error on which the
context has been attached. For details about the interaction between
context and downcasting, see here.
sourcepub fn downcast_ref<E>(&self) -> Option<&E> where
E: 'static + Display + Debug + Send + Sync,
pub fn downcast_ref<E>(&self) -> Option<&E> where
E: 'static + Display + Debug + Send + Sync,
Downcast this error object by reference.
Example
// If the error was caused by redaction, then return a tombstone instead
// of the content.
match root_cause.downcast_ref::<DataStoreError>() {
Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)),
None => Err(error),
}
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
Blanket Implementations
sourceimpl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
sourcepub fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
pub fn pointer_metadata(
&<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more