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

Support returning Result/Option<impl Trait> #126

Open
joshwd36 opened this issue Apr 3, 2021 · 1 comment
Open

Support returning Result/Option<impl Trait> #126

joshwd36 opened this issue Apr 3, 2021 · 1 comment
Labels
A-auto_enum Area: #[auto_enum] C-enhancement Category: A new feature or an improvement for an existing one

Comments

@joshwd36
Copy link

joshwd36 commented Apr 3, 2021

I've got a situation where a function returns something like Result<impl Iterator<Item = &str>, MyError>, and it would be very useful to be able to use auto_enum on it. Is this technically possible, or is there perhaps a workaround for it?

@taiki-e taiki-e added A-auto_enum Area: #[auto_enum] C-enhancement Category: A new feature or an improvement for an existing one labels Apr 8, 2021
@taiki-e
Copy link
Owner

taiki-e commented Apr 8, 2021

I think we can probably support something like this:

#[auto_enum(fmt::Debug)]
fn f() -> Option<impl fmt::Debug> {

    if ... {
        let opt = ...;
        // converted to `return opt.map(|some| Enum::A(some));`
        return opt;
    }

    if ... {
        // converted to `return Some(Enum::B(...))`
        return Some(...)
    }

    // converted to `Some(Enum::C(...))`
    Some(...)
}

related: #106

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-auto_enum Area: #[auto_enum] C-enhancement Category: A new feature or an improvement for an existing one
Projects
None yet
Development

No branches or pull requests

2 participants