On 14/07/14 03:33 PM, Robin Kruppe wrote: > > Second, the signature of MyClass::new() in your example is... unusual. > The return type unnecessarily narrow (returns a trait object instead of > the concrete type, even though callers have to know the concrete type > anyway to call new()) and does a pointless allocation as a consequence. > Just return a MyClass by value. If the call site needs polymorphism, > it's trivial to add (box MyClass::new() as Box<IMyClass>) and more > flexible (can use different smart pointers, or a borrowed reference for > short-lived uses). If there are numerous call sites and they all need > need trait objects, your design MAY be overly polymorphism-oriented for > the taste of Rustaceans.
The trait object also results in dynamic dispatch and indirect access to the object, in addition to the memory allocation.
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
