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

Implement iter_chain on the type that derives Error #8

Open
prasannavl opened this issue Oct 10, 2019 · 1 comment
Open

Implement iter_chain on the type that derives Error #8

prasannavl opened this issue Oct 10, 2019 · 1 comment
Labels

Comments

@prasannavl
Copy link

prasannavl commented Oct 10, 2019

I think it'd be immensely useful if iter_chain can be added on the type that derives Error and delegated to std::error::Error's iter_chain on nightlies with error_iter feature. Sure, one can always convert it into the std::error trait object and do it from there, but I think this will be ergonomic to have it right on the type.

https://doc.rust-lang.org/std/error/trait.Error.html#method.iter_chain

@dtolnay
Copy link
Owner

dtolnay commented Oct 11, 2019

Thanks, I would consider doing this after the signature of iter_chain is stable in std. For now you can get the same behavior by an extension trait:

pub trait IterChain: std::error::Error + 'static {
    fn iter_chain(&self) -> ErrorIter;
}

impl<T: std::error::Error + 'static> IterChain for T {
    fn iter_chain(&self) -> ErrorIter {
        /* ... */
    }
}
use thiserror::Error;

#[derive(Error, Debug)]
pub struct MyError;

fn main() {
    let err = MyError;
    let _ = err.iter_chain(); // works
}

@dtolnay dtolnay added the later label Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants