My proposal is not to generate one enum per Trait for the whole project, but generate different enums: one per usage site, and to define the number of variants in them based on the context of use.
Let's consider we have 3 different structs that implement some trait:
struct A { /* fields omitted */ }
struct B { /* fields omitted */ }
struct C { /* fields omitted */ }
trait Trait { /* body omitted */ }
impl Trait for A { /* impls omitted */ }
impl Trait for B { /* impls omitted */ }
impl Trait for C { /* impls omitted */ }
fn main() {
let mut foo = Vec::<static Trait>::new();
// static Trait is being translated into enum with 2 variants (A, B)
foo.push(A::new());
foo.push(B::new());
let mut bar = Vec::<static Trait>::new();
// static Trait is being translated into enum with 3 variants (A, B, C)
bar.push(A::new());
bar.push(B::new());
bar.push(C::new())
}
Here, foo's inner type would be an enum with 2 variants (A and B) and bar's one would have 3 variants (A, B and C). Because of the context.