Skip to content

Handle traits whose methods return Result<Self, E> and Option

I noticed that enum_dispatch conveniently handles trait methods that return Self. Nice!

For what I'm working on, it would be useful to also support wrapped Self. For example Result<Self, String> and Option<Self>.

Since From and Into is already implemented for all the variants, just from my quick playing around, it looks like something like the following is sufficient.

match self {
            MyTraitEnum::Foo(inner) => {
                MyTrait::maybe_smaller(inner, __enum_dispatch_arg_0).map(Into::into)
            }
...

I'll try to implement it and send a submission.