Struct Error

Source
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 of error_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

Source

pub fn from_kind(kind: ErrorKind) -> Error

Constructs an error from a kind, and generates a backtrace.

Source

pub fn with_chain<E, K>(error: E, kind: K) -> Error
where E: Error + Send + 'static, K: Into<ErrorKind>,

Constructs a chained error from another error and a kind, and generates a backtrace.

Source

pub fn kind(&self) -> &ErrorKind

Returns the kind of the error.

Source

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}
Source

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>§

Source

pub fn description(&self) -> &str

A string describing the error kind.

Trait Implementations§

Source§

impl ChainedError for Error

Source§

type ErrorKind = ErrorKind

Associated kind type.
Source§

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
where E: Error + Send + 'static, K: Into<Self::ErrorKind>,

Constructs a chained error from another error and a kind, and generates a backtrace.
Source§

fn kind(&self) -> &Self::ErrorKind

Returns the kind of the error.
Source§

fn iter(&self) -> ErrorChainIter<'_>

Iterates over the error chain.
Source§

fn backtrace(&self) -> Option<&Backtrace>

Returns the backtrace associated with this error.
Source§

fn display<'a>(&'a self) -> Display<'a, Self>

Returns an object which implements Display for printing the full context of this error. Read more
Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Error

Source§

type Target = ErrorKind

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl<'a> From<&'a str> for Error

Source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for Error

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for ErrorKind

Source§

fn from(e: Error) -> Self

Converts to this type from the input type.
Source§

impl From<ErrorKind> for Error

Source§

fn from(e: ErrorKind) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Error

Source§

fn from(s: String) -> 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.