1
submitted 4 years ago by kixik@lemmy.ml to c/rust@lemmy.ml

Just sharing from r/rust

top 3 comments
sorted by: hot top new old
[-] nachtigall@feddit.de 1 points 4 years ago

Oh please not. Spare us from the C++ type-polymorphy nightmare. Traits are so much better than inheritance.

[-] caellian@mastodon.social 1 points 4 years ago

@kixik Inheritance can always be substituted by composition which is what #Rust does pretty well. Constexpr isn't on C++ level, but I guess you can generate code from build script so there's ways around it.
As for virtual functions - Traits are effectively to virtual function lookup table declarations that get used by dyn SomeTrait type. So calling a fn on Box\<dyn T\> generates VMT lookup.

[-] caellian@mastodon.social 1 points 4 years ago

@kixik Thanks to good macro system Rust can (via enum_dispatch) transform those lookups into a switch statement which is best of both worlds IMO.

load more comments
view more: next ›
this post was submitted on 14 Nov 2022
1 points (66.7% liked)

Rust Programming

9435 readers
1 users here now

founded 7 years ago
MODERATORS