Skip to content

Commit 2596119

Browse files
committed
Update to latest unstable API
- Renames `chain` to `sources` following rust-lang/rust#100955
1 parent 6289730 commit 2596119

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
22
name = "error-iter"
3-
description = "Error::chain on stable Rust"
3+
description = "Error::sources on stable Rust"
44
repository = "https://github.com/parasyte/error-iter"
55
version = "0.2.0"
66
authors = ["Jay Oster <[email protected]>"]
77
edition = "2018"
88
readme = "README.md"
9-
keywords = ["chain", "error", "iter", "iterator", "sources"]
9+
keywords = ["error", "iter", "iterator", "recursive", "sources"]
1010
categories = ["rust-patterns"]
1111
license = "MIT"
1212

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![GitHub Sponsors](https://img.shields.io/github/sponsors/parasyte)](https://github.com/sponsors/parasyte "Sponsors")
88
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
99

10-
Use [`Error::chain`](https://doc.rust-lang.org/nightly/std/error/trait.Error.html#method.chain) on stable Rust.
10+
Use [`Error::sources`](https://doc.rust-lang.org/nightly/std/error/trait.Error.html#method.sources) on stable Rust.
1111

1212
## MSRV
1313

@@ -17,7 +17,7 @@ Compiles on Rust 1.31.0, but does not return the tail source. (Tests fail on any
1717

1818
## What is this?
1919

20-
`Error::chain` is incredibly useful for providing error context in Rust applications. For motivation, see [RFC 2504](https://github.com/rust-lang/rfcs/blob/master/text/2504-fix-error.md). This iterator is available in nightly compilers with [#58520](https://github.com/rust-lang/rust/issues/58520) tracking stabilization.
20+
`Error::sources` is incredibly useful for providing error context in Rust applications. For motivation, see [RFC 2504](https://github.com/rust-lang/rfcs/blob/master/text/2504-fix-error.md). This iterator is available in nightly compilers with [#58520](https://github.com/rust-lang/rust/issues/58520) tracking stabilization.
2121

2222
This crate does not attempt to be 100% compatible with the stabilization effort, but does want to provide very similar functionality to stable Rust.
2323

examples/simple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
let error = Error::from(IoError::new(ErrorKind::Other, "oh no!"));
1818

1919
eprintln!("Error: {}", error);
20-
for source in error.chain().skip(1) {
20+
for source in error.sources().skip(1) {
2121
eprintln!(" Caused by: {}", source);
2222
}
2323
}

src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//! let error = Error::from(IoError::new(ErrorKind::Other, "oh no!"));
2121
//!
2222
//! eprintln!("Error: {}", error);
23-
//! for source in error.chain().skip(1) {
23+
//! for source in error.sources().skip(1) {
2424
//! eprintln!(" Caused by: {}", source);
2525
//! }
2626
//! }
@@ -51,7 +51,7 @@ impl<'a> Iterator for ErrorIterator<'a> {
5151
///
5252
/// The default implementation provides iterators for any type that implements `std::error::Error`.
5353
pub trait ErrorIter: std::error::Error + Sized + 'static {
54-
/// Create an iterator over the error and its chained sources.
54+
/// Create an iterator over the error and its recursive sources.
5555
///
5656
/// ```
5757
/// use error_iter::ErrorIter;
@@ -70,14 +70,14 @@ pub trait ErrorIter: std::error::Error + Sized + 'static {
7070
///
7171
/// let error = Error::Nested(Box::new(Error::Leaf));
7272
///
73-
/// let mut iter = error.chain();
73+
/// let mut iter = error.sources();
7474
///
7575
/// assert_eq!("Nested error: Leaf error".to_string(), iter.next().unwrap().to_string());
7676
/// assert_eq!("Leaf error".to_string(), iter.next().unwrap().to_string());
7777
/// assert!(iter.next().is_none());
7878
/// assert!(iter.next().is_none());
7979
/// ```
80-
fn chain(&self) -> ErrorIterator {
80+
fn sources(&self) -> ErrorIterator {
8181
ErrorIterator { inner: Some(self) }
8282
}
8383
}
@@ -99,10 +99,10 @@ mod tests {
9999
impl ErrorIter for Error {}
100100

101101
#[test]
102-
fn iter_chain_ok() {
102+
fn iter_sources_ok() {
103103
let error = Error::Nested(Box::new(Error::Nested(Box::new(Error::Leaf))));
104104

105-
let mut iter = error.chain();
105+
let mut iter = error.sources();
106106

107107
assert_eq!(
108108
"Nested error: Nested error: Leaf error".to_string(),

0 commit comments

Comments
 (0)