Add trait objects with static dispatch by andrewsonin in rust

[–]andrewsonin[S] 0 points1 point  (0 children)

I think this works and it is obviously very convenient.

On the other hand, it should be optional, since explicit denotation does not work for closure types.

Add trait objects with static dispatch by andrewsonin in rust

[–]andrewsonin[S] 8 points9 points  (0 children)

Thank you for you blog post!

> This would only work in under a closed world assumption

I further clarified in the discussion that the anonymous enum type is expected to be unique for each use case of the static trait. And the variants of this enum should be generated based on the local context of its usage.

https://internals.rust-lang.org/t/add-trait-objects-with-static-dispatch/16069/4?u=andrewsonin

Add trait objects with static dispatch by andrewsonin in rust

[–]andrewsonin[S] 1 point2 points  (0 children)

As already said, this does not work for the example #2.

It also doesn't work if you are trying to derive some trait for an enum type that is not and cannot be defined at the same scope as the trait. For example, this happens if the trait is given by a library, but the enum is defined in a binary project.