Skip to content
Myr

Rename Errors to Chain

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent 23a0032 · Browse files · 2 files+9 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+9 added−9 removed

  • other:+9 added−9 removed

2 files+9 added−9 removed

modified:src/error.rs+8 added-8 removed
86 unmodified lines
87 .or_else(|| self.inner.error().backtrace())88 .expect("backtrace capture failed")89 }9091 /// An iterator of errors contained by this Error.91 /// An iterator of the chain of source errors contained by this Error.92 ///93 /// This iterator will visit every error in the "cause chain" of this error93 /// This iterator will visit every error in the cause chain of this error94 /// object, beginning with the error that this error object was created95 /// from.96 pub fn errors(&self) -> Errors<'_> {97 Errors {96 pub fn chain(&self) -> Chain {97 Chain {98 next: Some(self.inner.error()),99 }100 }101
72 unmodified lines
174impl Debug for Error {175 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {176 writeln!(f, "{}", self.inner.error())?;177178 let mut errors = self.errors().skip(1).enumerate();178 let mut errors = self.chain().skip(1).enumerate();179180 if let Some((n, error)) = errors.next() {181 writeln!(f, "\ncaused by:")?;182 writeln!(f, "\t{}: {}", n, error)?;
94 unmodified lines
277 }278 }279}280281/// Iterator of errors in an `Error`.282pub struct Errors<'a> {281/// Iterator of a chain of source errors.282pub struct Chain<'a> {283 next: Option<&'a (dyn StdError + 'static)>,284}285286impl<'a> Iterator for Errors<'a> {286impl<'a> Iterator for Chain<'a> {287 type Item = &'a (dyn StdError + 'static);288289 fn next(&mut self) -> Option<Self::Item> {290 let next = self.next.take()?;
51 unmodified lines
modified:src/lib.rs+1 added-1 removed
4 unmodified lines
5mod error;67pub use crate::as_dyn_error::AsDynError;8pub use crate::context::Context;9pub use crate::error::{Error, Errors};9pub use crate::error::{Chain, Error};1011/// `Result<T, Error>`12pub type Result<T> = std::result::Result<T, Error>;13
20 unmodified lines