pub struct Error(pub ErrorKind, _);
Expand description
The Error type.
This tuple struct is made of two elements:
- an
ErrorKind
which is used to determine the type of the error. - An internal
State
, not meant for direct use outside oferror_chain
internals, containing:- a backtrace, generated when the error is created.
- an error chain, used for the implementation of
Error::cause()
.
Tuple Fields§
§0: ErrorKind
The kind of the error.
Implementations§
Source§impl Error
impl Error
Sourcepub fn from_kind(kind: ErrorKind) -> Error
pub fn from_kind(kind: ErrorKind) -> Error
Constructs an error from a kind, and generates a backtrace.
Sourcepub fn with_chain<E, K>(error: E, kind: K) -> Error
pub fn with_chain<E, K>(error: E, kind: K) -> Error
Constructs a chained error from another error and a kind, and generates a backtrace.
Sourcepub fn iter(&self) -> ErrorChainIter<'_>
pub fn iter(&self) -> ErrorChainIter<'_>
Iterates over the error chain.
Examples found in repository?
examples/printer.rs (line 26)
5fn main() {
6 if let Some(path) = std::env::args().nth(1) {
7 match openapi::from_path(path) {
8 Ok(spec) => {
9 /*for (path, op) in spec.paths {
10 println!("{}", path);
11 println!("{:#?}", op);
12 }
13 for (name, definition) in spec.definitions {
14 println!("{}", name);
15 println!("{:#?}", definition);
16 }*/
17 println!("{}", openapi::to_json(&spec).unwrap());
18 }
19 Err(e) => {
20
21 let stderr = &mut ::std::io::stderr();
22 let errmsg = "Error writing to stderr";
23
24 writeln!(stderr, "error: {}", e).expect(errmsg);
25
26 for e in e.iter().skip(1) {
27 writeln!(stderr, "caused by: {}", e).expect(errmsg);
28 }
29
30 // The backtrace is not always generated. Try to run this example
31 // with `RUST_BACKTRACE=1`.
32 if let Some(backtrace) = e.backtrace() {
33 writeln!(stderr, "backtrace: {:?}", backtrace).expect(errmsg);
34 }
35
36 ::std::process::exit(1);
37 }
38 }
39 }
40}
Sourcepub fn backtrace(&self) -> Option<&Backtrace>
pub fn backtrace(&self) -> Option<&Backtrace>
Returns the backtrace associated with this error.
Examples found in repository?
examples/printer.rs (line 32)
5fn main() {
6 if let Some(path) = std::env::args().nth(1) {
7 match openapi::from_path(path) {
8 Ok(spec) => {
9 /*for (path, op) in spec.paths {
10 println!("{}", path);
11 println!("{:#?}", op);
12 }
13 for (name, definition) in spec.definitions {
14 println!("{}", name);
15 println!("{:#?}", definition);
16 }*/
17 println!("{}", openapi::to_json(&spec).unwrap());
18 }
19 Err(e) => {
20
21 let stderr = &mut ::std::io::stderr();
22 let errmsg = "Error writing to stderr";
23
24 writeln!(stderr, "error: {}", e).expect(errmsg);
25
26 for e in e.iter().skip(1) {
27 writeln!(stderr, "caused by: {}", e).expect(errmsg);
28 }
29
30 // The backtrace is not always generated. Try to run this example
31 // with `RUST_BACKTRACE=1`.
32 if let Some(backtrace) = e.backtrace() {
33 writeln!(stderr, "backtrace: {:?}", backtrace).expect(errmsg);
34 }
35
36 ::std::process::exit(1);
37 }
38 }
39 }
40}
Methods from Deref<Target = ErrorKind>§
Sourcepub fn description(&self) -> &str
pub fn description(&self) -> &str
A string describing the error kind.
Trait Implementations§
Source§impl ChainedError for Error
impl ChainedError for Error
Source§fn from_kind(kind: Self::ErrorKind) -> Self
fn from_kind(kind: Self::ErrorKind) -> Self
Constructs an error from a kind, and generates a backtrace.
Source§fn with_chain<E, K>(error: E, kind: K) -> Self
fn with_chain<E, K>(error: E, kind: K) -> Self
Constructs a chained error from another error and a kind, and generates a backtrace.
Source§fn iter(&self) -> ErrorChainIter<'_>
fn iter(&self) -> ErrorChainIter<'_>
Iterates over the error chain.
Source§impl Error for Error
impl Error for Error
Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§fn cause(&self) -> Option<&dyn Error>
fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
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