Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest unstable API #7

Merged
merged 1 commit into from
Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "error-iter"
description = "Error::chain on stable Rust"
description = "Error::sources on stable Rust"
repository = "https://github.com/parasyte/error-iter"
version = "0.2.0"
authors = ["Jay Oster <jay@kodewerx.org>"]
edition = "2018"
readme = "README.md"
keywords = ["chain", "error", "iter", "iterator", "sources"]
keywords = ["error", "iter", "iterator", "recursive", "sources"]
categories = ["rust-patterns"]
license = "MIT"

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![GitHub Sponsors](https://img.shields.io/github/sponsors/parasyte)](https://github.com/sponsors/parasyte "Sponsors")
[![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)

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

## MSRV

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

## What is this?

`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.
`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.

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

Expand Down
2 changes: 1 addition & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() {
let error = Error::from(IoError::new(ErrorKind::Other, "oh no!"));

eprintln!("Error: {}", error);
for source in error.chain().skip(1) {
for source in error.sources().skip(1) {
eprintln!(" Caused by: {}", source);
}
}
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//! let error = Error::from(IoError::new(ErrorKind::Other, "oh no!"));
//!
//! eprintln!("Error: {}", error);
//! for source in error.chain().skip(1) {
//! for source in error.sources().skip(1) {
//! eprintln!(" Caused by: {}", source);
//! }
//! }
Expand Down Expand Up @@ -51,7 +51,7 @@ impl<'a> Iterator for ErrorIterator<'a> {
///
/// The default implementation provides iterators for any type that implements `std::error::Error`.
pub trait ErrorIter: std::error::Error + Sized + 'static {
/// Create an iterator over the error and its chained sources.
/// Create an iterator over the error and its recursive sources.
///
/// ```
/// use error_iter::ErrorIter;
Expand All @@ -70,14 +70,14 @@ pub trait ErrorIter: std::error::Error + Sized + 'static {
///
/// let error = Error::Nested(Box::new(Error::Leaf));
///
/// let mut iter = error.chain();
/// let mut iter = error.sources();
///
/// assert_eq!("Nested error: Leaf error".to_string(), iter.next().unwrap().to_string());
/// assert_eq!("Leaf error".to_string(), iter.next().unwrap().to_string());
/// assert!(iter.next().is_none());
/// assert!(iter.next().is_none());
/// ```
fn chain(&self) -> ErrorIterator {
fn sources(&self) -> ErrorIterator {
ErrorIterator { inner: Some(self) }
}
}
Expand All @@ -99,10 +99,10 @@ mod tests {
impl ErrorIter for Error {}

#[test]
fn iter_chain_ok() {
fn iter_sources_ok() {
let error = Error::Nested(Box::new(Error::Nested(Box::new(Error::Leaf))));

let mut iter = error.chain();
let mut iter = error.sources();

assert_eq!(
"Nested error: Nested error: Leaf error".to_string(),
Expand Down