[rust-dev] C++ to Rust - Is that about right?

Daniel Micay danielmicay at gmail.com
Mon Jul 14 12:44:04 PDT 2014


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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140714/53ef1242/attachment.sig>


More information about the Rust-dev mailing list