Is it possible to tell the compiler that I want a trait object that is Sized to accommodate a known set of structs implementing the Trait?
That is, if I have a public factory function for instantiating a Something and I have two different private somethings that implement the Something interface: FooSomething and BarSomething and I don't want heap allocation (i.e. I don't want the factory to return Box<Something>, can I make Something a trait and tell the compiler that the trait objects should be Sized to accommodate the larger of FooSomething and BarSomething?
Or do I need to make Something a struct that has an enum member that is a tagged union of FooSomething and BarSomething with manually-written dispatch that matches on the enum?
Thanks. Ideally, there'd be a way to ask the compiler to generate the mechanic stuff instead of having to write it manually, using macros or using Python to generate Rust.