mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-30 06:21:52 +00:00
Add example to Chain iterator
This commit is contained in:
parent
d159b79a63
commit
feb9f33dde
18
src/error.rs
18
src/error.rs
@ -423,6 +423,24 @@ impl ErrorImpl<()> {
|
||||
}
|
||||
|
||||
/// Iterator of a chain of source errors.
|
||||
///
|
||||
/// This type is the iterator returned by [`Error::chain`].
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use anyhow::Error;
|
||||
/// use std::io;
|
||||
///
|
||||
/// pub fn underlying_io_error_kind(error: &Error) -> Option<io::ErrorKind> {
|
||||
/// for cause in error.chain() {
|
||||
/// if let Some(io_error) = cause.downcast_ref::<io::Error>() {
|
||||
/// return Some(io_error.kind());
|
||||
/// }
|
||||
/// }
|
||||
/// None
|
||||
/// }
|
||||
/// ```
|
||||
pub struct Chain<'a> {
|
||||
next: Option<&'a (dyn StdError + 'static)>,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user