auto_enums icon indicating copy to clipboard operation
auto_enums copied to clipboard

Support returning Result/Option<impl Trait>

Open joshwd36 opened this issue 4 years ago • 1 comments

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?

joshwd36 avatar Apr 03 '21 16:04 joshwd36

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

taiki-e avatar Apr 08 '21 12:04 taiki-e