Is it possible to construct a "trait object" without instantiating the struct, IF the trait only contains static methods?
For example:
trait Foo {
fn bar() -> u8;
fn baz() -> String;
}
fn<T: Foo> qux() -> Box<dyn Foo> {
Box::new(T as Foo) <--- Compile error
}
I think this should be theoretically possible, since this works:
struct ManualFoo {
pub bar_fn: fn() -> u8,
pub baz_fn: fn() -> String
}
fn<T: Foo> qux() -> ManualFoo {
ManualFoo {
bar_fn: T::bar,
baz_fn: T::baz
}
Which kinda is a manually declared trait object, but I'm wondering if there is something I'm missing, or if the compiler actually supports this with some syntax?