pub struct Error(/* private fields */);
Expand description
A general-purpose error with a “kind” from Google’s canonical error space.
This currently tracks:
- The error “kind”, taken from Google’s canonical error space.
- A human-readable message.
- An optional source/cause, exposed through
std::error::Error::cause
. - An optional backtrace. This is present if
coded
was compiled with thebacktrace
orunstable_std_backtrace
feature flags and the program was run withRUST_BACKTRACE
orRUST_LIB_BACKTRACE
set as described atstd::backtrace
.
The Display
impl will display a short summary of this error itself.
It won’t display the chain of sources or the backtrace.
To display this error along with its causes and stack trace, use the chain
method.
Implementations§
Source§impl Error
impl Error
Sourcepub fn new(kind: ErrorKind, msg: String) -> Self
pub fn new(kind: ErrorKind, msg: String) -> Self
Returns a new error with the given kind and message.
Sourcepub fn wrap<E: StdError + 'static>(
kind: ErrorKind,
msg: Option<String>,
source: E,
) -> Self
pub fn wrap<E: StdError + 'static>( kind: ErrorKind, msg: Option<String>, source: E, ) -> Self
Returns a new error wrapping a source with no additional message.
Sourcepub fn chain(&self) -> impl Display + '_
pub fn chain(&self) -> impl Display + '_
Returns a borrowed value which can display not only this error but also the full chain of causes and (where applicable) the stack trace.
The exact format may change. Currently, it displays the stack trace for the current error but not any of the sources.
Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl From<ErrorBuilder> for Error
impl From<ErrorBuilder> for Error
Source§fn from(builder: ErrorBuilder) -> Self
fn from(builder: ErrorBuilder) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for Error
impl !RefUnwindSafe for Error
impl !Send for Error
impl !Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more