Skip to content

Traits for ?? #2019

Description

@jD91mZM2

I sadly barely get to use ?, because I find myself not using Result<> as often because it just doesn't fit in. For example, I instead return a struct with a success boolean at one point, or I wanna completely ignore errors the other. There should be a way for ? to detect return values and use some trait to return an error.

For example:

struct Stuff {
    // some fields here
    success: bool
}

impl Try for Stuff {
    fn err(error: std::error::Error) -> Stuff {
        Stuff{
            // some fields here
            success: false;
        }
    }
}

Also, () return values would implement the trait as well, but return.. well... nothing.

If the suggestion sounds stupid to you - sorry for disturbing :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions