From feb9f33ddee11a5a0f48af8bc0dcebdae0551d95 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 6 Oct 2019 16:13:19 -0400 Subject: [PATCH] Add example to Chain iterator --- src/error.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/error.rs b/src/error.rs index bcc8921..950167b 100644 --- a/src/error.rs +++ b/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 { +/// for cause in error.chain() { +/// if let Some(io_error) = cause.downcast_ref::() { +/// return Some(io_error.kind()); +/// } +/// } +/// None +/// } +/// ``` pub struct Chain<'a> { next: Option<&'a (dyn StdError + 'static)>, }