rust-lang-deprecated/failure

No method iter_chain() is defined for Context<T>

vimmerru opened this issue · 4 comments

Hi, i am trying to use iter_chain() for Context<T> and compiler says that no such method defined. May be it is because it only exists in impl block of Fail and isn't defined in pub trait statement.

I still can use causes(), but it produces deprecation warning.

Any help with this?

Works for me:

extern crate failure;

use failure::Fail;
use std::io;


fn main() {
    let err = io::Error::new(io::ErrorKind::Other, "This is an error");
    let err_with_ctx = err.context("Testing");
    for cause in Fail::iter_chain(&err_with_ctx) {
        println!("{}", cause);
    }
}

But the following will fail

 for cause in err_with_ctx.iter_chain() {
     println!("{}", cause);
 }

It is hard to understand that Fail::iter_chain(&err_with_ctx) form should be used. Very non-usual way to call methods with &self param in rust. Anyway thanks for an example, it solves my problem.

Correct. This change was intentionally made because that cannot be supported without creating situations where ambiguity cannot be resolved. I don't know a way around that.

Hi there!

Would it be possible to add such an example in the documentation, please?
I also didn't understand it at the beginning.

Thanks beforehand!