Add example to Chain iterator

This commit is contained in:
David Tolnay 2019-10-06 16:13:19 -04:00
parent d159b79a63
commit feb9f33dde
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -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)>,
}