Skip to main content

error2/
kind.rs

1/// Represents the kind of error after downcasting [`BoxedError2`](crate::BoxedError2).
2///
3/// Used to distinguish between standard library errors and Error2 errors
4/// when downcasting type-erased errors.
5///
6/// # Variants
7///
8/// - `Std`: Error from `std::error::Error` (has its own backtrace)
9/// - `Err2`: Error implementing [`Error2`](crate::Error2) (reuses parent backtrace)
10///
11/// # Example
12///
13/// ```
14/// use std::io;
15///
16/// use error2::{kind::ErrorKind, prelude::*};
17///
18/// # fn example() -> Result<(), BoxedError2> {
19/// let err = std::io::Error::from(std::io::ErrorKind::NotFound);
20/// let boxed = BoxedError2::from_std(err);
21///
22/// // Downcast to get the ErrorKind
23/// match boxed.downcast_ref::<io::Error>() {
24///     Some(ErrorKind::Std { source, backtrace }) => {
25///         println!("Std error: {}", source);
26///     }
27///     Some(ErrorKind::Err2 { source }) => {
28///         println!("Error2: {}", source);
29///     }
30///     None => {}
31/// }
32/// # Ok(())
33/// # }
34/// ```
35pub enum ErrorKind<E, B> {
36    /// Standard library error with its own backtrace.
37    Std {
38        /// The underlying error.
39        source: E,
40        /// The error's backtrace.
41        backtrace: B,
42    },
43    /// Error2 error that reuses the parent's backtrace.
44    Err2 {
45        /// The underlying Error2 instance.
46        source: E,
47    },
48}