Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 026f709

Browse files
ahmedcharlesYamakaky
authored andcommitted
Rename ErrorChainIter to Iter #168. (#196)
* Rename ErrorChainIter to Iter. Fixes #168. * Make ErrorChainIter's field private. Fixes #178.
1 parent 252a7a3 commit 026f709

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- [Make `ErrorChainIter`'s field private](https://github.com/brson/error-chain/issues/178)
4+
- [Rename `ErrorChainIter` to `Iter`](https://github.com/brson/error-chain/issues/168)
35
- [Implement `Debug` for `ErrorChainIter`](https://github.com/brson/error-chain/issues/169)
46
- [Rename `ChainedError::display` to `display_chain`](https://github.com/brson/error-chain/issues/180)
57
- [Add a new method for `Error`: `chain_err`.](https://github.com/brson/error-chain/pull/141)

src/error_chain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ macro_rules! error_chain_processed {
9696
self.kind()
9797
}
9898

99-
fn iter(&self) -> $crate::ErrorChainIter {
100-
$crate::ErrorChainIter(Some(self))
99+
fn iter(&self) -> $crate::Iter {
100+
$crate::Iter::new(Some(self))
101101
}
102102

103103
fn chain_err<F, EK>(self, error: F) -> Self
@@ -151,7 +151,7 @@ macro_rules! error_chain_processed {
151151
}
152152

153153
/// Iterates over the error chain.
154-
pub fn iter(&self) -> $crate::ErrorChainIter {
154+
pub fn iter(&self) -> $crate::Iter {
155155
$crate::ChainedError::iter(self)
156156
}
157157

src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,16 @@ pub mod example_generated;
495495

496496
#[derive(Debug)]
497497
/// Iterator over the error chain using the `Error::cause()` method.
498-
pub struct ErrorChainIter<'a>(pub Option<&'a error::Error>);
498+
pub struct Iter<'a>(Option<&'a error::Error>);
499499

500-
impl<'a> Iterator for ErrorChainIter<'a> {
500+
impl<'a> Iter<'a> {
501+
/// Returns a new iterator over the error chain using `Error::cause()`.
502+
pub fn new(err: Option<&'a error::Error>) -> Iter<'a> {
503+
Iter(err)
504+
}
505+
}
506+
507+
impl<'a> Iterator for Iter<'a> {
501508
type Item = &'a error::Error;
502509

503510
fn next<'b>(&'b mut self) -> Option<&'a error::Error> {
@@ -542,7 +549,7 @@ pub trait ChainedError: error::Error + Send + 'static {
542549
fn kind(&self) -> &Self::ErrorKind;
543550

544551
/// Iterates over the error chain.
545-
fn iter(&self) -> ErrorChainIter;
552+
fn iter(&self) -> Iter;
546553

547554
/// Returns the backtrace associated with this error.
548555
fn backtrace(&self) -> Option<&Backtrace>;

0 commit comments

Comments
 (0)