The compiler tells you the exact reason why this does not work:
error[E0038]: the trait `IBoo` cannot be made into an object --> src/main.rs:2:5 | 2 | fn new() -> Box<IBoo>; | ^^^^^^^^^^^^^^^^^^^^^^ the trait `IBoo` cannot be made into an object | = note: method `new` has no receiver
Pay attention to the last line. He tells you that the cause of the error is that new() is independent of the existence of an instance of the value that implements the IBoo attribute.
Without using any pointer to self , the method cannot be called by dynamic dispatch. If it cannot be caused by dynamic dispatching, it means that it cannot get into the vtable associated with the symbol. Must be related to vtable, because it works something like Box<IBoo> . Some time ago, the main developers of Rust decided that even one βnon-object safeβ method in the attribute disqualified the whole trait from being used as an object.
In other words: since you have defined a method that cannot be dynamically dispatched, the IBoo attribute is generally disqualified from use with dynamically dispatched.
If you want some kind of design function, you need to have a different way of writing it. It could be using simple function pointers or IBooFactory traits, as you could with Java.
DK.
source share