5 ms·
It also makes multiple inheritance (which Rust has, through Java-like interfaces) easy to implement, and fast at runtime. The virtual inheritance of C++ is a re
by pcwalton 12y ago
It also makes multiple inheritance (which Rust has, through Java-like interfaces) easy to implement, and fast at runtime. The virtual inheritance of C++ is a real mess, by contrast [1].
[1]: http://www.phpcompiler.org/articles/virtualinheritance.html http://www.phpcompiler.org/articles/virtualinheritance.html
Edit: I don't mean to bash C++ here, BTW; the skinny-pointer approach has a lot of benefits when all you need is single inheritance (and there are early-stage proposals to add it to Rust too). But I don't think it works well for multiple inheritance.
- deleted 12y ago[deleted]
- deleted 12y ago[deleted]
- fmstephe 12y agoI apologise in advance that this may not be most appropriate place to ask this question. I am looking for a Rust tutorial. It looks like there was one, but it was deprecated in favour of 'the book'. But 'the book' doesn't seem to have a tutorial yet. Are there any tutorial's running through how to build some small piece of working software. I found the Golang tutorial, where you build a very basic blog extremely enjoyable. Does Rust have anything similar? https://golang.org/doc/articles/wiki/ https://golang.org/doc/articles/wiki/ Thanks
- steveklabnik 12y agoThe book basically has two sets of tutorials: the "Syntax and Semantics" section is a bottom-up tutorial, and the "Learn Rust" section is a project-based, more top-down one. It's true that only one chapter of Learn Rust has landed at the moment. It's basically what I'm doing right now. Should have two or three more chapters over the next few days.
- fmstephe 12y agoGreat, thanks Steve.
- deleted 12y ago[deleted]
- kalmar 12y agoWhat is the representation for a type like Box<Reader+Writer>? Is there an extra indirection to get each of the vtables? Is there synthesized combined trait type and just one vtable pointer?
- Jweb_Guru 12y agoI am pretty sure you can't actually construct such a type (at least not at the moment) so Rust sort of sidesteps the question.
- Manishearth 12y agoIIRC you can.
- burntsushi 12y agoIt's early, so maybe I'm doing something stupid, but it looks like you can't! http://is.gd/9Y1HiS http://is.gd/9Y1HiS --- (I'm kind of surprised by the error message.)
- Rusky 12y agoI get this when I try something like `as Box<Read+Write>` error: only the builtin traits can be used as closure or object bounds [E0225]
- Manishearth 12y agoTIL; thanks :)
- drbawb 12y agoYou can sort of emulate this by having a trait which inherits from two other traits. (e.g: http://is.gd/SWZ9Ya http://is.gd/SWZ9Ya) In which case you'll have a single vtable for the "synthesized" trait object.