Struct libmodbus_rs::prelude::Error
[−]
[src]
pub struct Error { /* fields omitted */ }
The Error
type, which can contain any failure.
Functions which accumulate many kinds of errors should return this type.
All failures can be converted into it, so functions which catch those
errors can be tried with ?
inside of a function that returns this kind
of error.
In addition to implementing Debug
and Display
, this type carries Backtrace
information, and can be downcast into the failure that underlies it for
more detailed inspection.
Methods
impl Error
[src]
fn cause(&self) -> &(Fail + 'static)
[src]
Returns a reference to the underlying cause of this Error
. Unlike the
method on Fail
, this does not return an Option
. The Error
type
always has an underlying failure.
fn backtrace(&self) -> &Backtrace
[src]
Gets a reference to the Backtrace
for this Error
.
If the failure this wrapped carried a backtrace, that backtrace will
be returned. Otherwise, the backtrace will have been constructed at
the point that failure was cast into the Error
type.
fn context<D>(self, context: D) -> Context<D> where
D: 'static + Send + Sync + Display,
[src]
D: 'static + Send + Sync + Display,
Provides context for this Error
.
This can provide additional information about this error, appropriate to the semantics of the current layer. That is, if you have a lower-level error, such as an IO error, you can provide additional context about what that error means in the context of your function. This gives users of this function more information about what has gone wrong.
This takes any type that implements Display
, as well as
Send
/Sync
/'static
. In practice, this means it can take a String
or a string literal, or a failure, or some other custom context-carrying
type.
fn compat(self) -> Compat<Error>
[src]
Wraps Error
in a compatibility type.
This type implements the Error
trait from std::error
. If you need
to pass failure's Error
to an interface that takes any Error
, you
can use this method to get a compatible type.
fn downcast<T>(self) -> Result<T, Error> where
T: Fail,
[src]
T: Fail,
Attempts to downcast this Error
to a particular Fail
type.
This downcasts by value, returning an owned T
if the underlying
failure is of the type T
. For this reason it returns a Result
- in
the case that the underlying error is of a different type, the
original Error
is returned.
fn root_cause(&self) -> &(Fail + 'static)
[src]
Returns the "root cause" of this error - the last value in the
cause chain which does not return an underlying cause
.
fn downcast_ref<T>(&self) -> Option<&T> where
T: Fail,
[src]
T: Fail,
Attempts to downcast this Error
to a particular Fail
type by
reference.
If the underlying error is not of type T
, this will return None
.
fn downcast_mut<T>(&mut self) -> Option<&mut T> where
T: Fail,
[src]
T: Fail,
Attempts to downcast this Error
to a particular Fail
type by
mutable reference.
If the underlying error is not of type T
, this will return None
.
fn causes(&self) -> Causes
[src]
Returns a iterator over the causes of the Error
, beginning with
the failure returned by the cause
method and ending with the failure
returned by root_cause
.
Trait Implementations
impl From<Error> for Error
[src]
impl<T> ResultExt<T, Error> for Result<T, Error>
[src]
fn compat(self) -> Result<T, Compat<Error>>
[src]
fn context<D>(self, context: D) -> Result<T, Context<D>> where
D: Display + Send + Sync + 'static,
[src]
D: Display + Send + Sync + 'static,
fn with_context<F, D>(self, f: F) -> Result<T, Context<D>> where
D: Display + Send + Sync + 'static,
F: FnOnce(&Error) -> D,
[src]
D: Display + Send + Sync + 'static,
F: FnOnce(&Error) -> D,
impl Display for Error
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
Formats the value using the given formatter. Read more
impl From<Error> for Box<Error + 'static>
[src]
impl<F> From<F> for Error where
F: Fail,
[src]
F: Fail,