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

iter_causes is only implemented on trait objects #248

@fitzgen

Description

@fitzgen

This means that one has to either use UFCS or casting into a trait object to actually use the method:

let e: failure::Error = get_the_error_from_somewhere();

// Have to use UFCS (to implicitly create a trait object):
for c in Fail::iter_causes(&e) {
    // ...
}

// or explicitly turn the error into a trait object:
for c in (&e as &Fail).iter_causes() {
    // ...
}

// but I really just want to do this:
for c in e.iter_causes() {
    // ...
}

iter_causes should also be a provided method for all implementations of the trait:

trait Fail {
    // ...

    fn iter_causes(&self) -> Causes {
        // the default implementation here...
    }
}

Note that adding an iter_causes method to failure::Error is sufficient to fix the first example, and let it use iter_causes directly, but it won't fix the issue for any other type that implements failure::Fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions