TL;DR: you don't need them as much as you may think, so don't let that scare you away!
Some languages prefer inheritance to express is-a relationships and composition to express has-a relationships. Some languages try to shoe horn is-a into being equivalent to has-a, but they usually have trouble expressing non-structural subtyping.
For the lack of a horseshoe, EquestrianDoctor.getLocalInstance().getHorseDispatcher().shoot();
(...)
http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom...
The good news is that's an extremely constrained sort of inheritance, very unlike traditional OO in that it doesn't have base classes--it's just a special extension to the trait (typeclass) system that allows you to require that structs begin with a certain set of fields. In fact, I don't even call it inheritance these days--I prefer the name "structural constraints".
[edit, on #rust it was explained to me that its only for pointers to structs, but thats fine by me]
Although with the right language support, it is useless, composition can stand for it (demo: Self)
Say I have an early-generated state tracker for a whole bunch of events propagating in an event loop somewhere, that I want discarded when all the events finish. They are all separate tasks in different threads, so I either need to have some job that just checks if they all finish to clean up, or pass around shared data structures. How would you do that in Rust?
For the example you mentioned, you could have the parent object of those tasks responsible for cleanup of the shared object (e.g. each thread's destructor calls a finish function on the parent object). This is just one possible implementation. I don't encounter this as much because I prefer a shared-nothing approach where possible.
edit:typo
[0] http://static.rust-lang.org/doc/master/extra/arc/struct.Arc.... [1] http://static.rust-lang.org/doc/master/extra/arc/struct.RWAr...
It's actually not too bad. The biggest problem with the docs currently is that it's a patched-together set of things people have written at random over the last few years. Mozilla has taken some concrete steps to address this, it'll be much better overall soon.
Now, some of the syntax for using them might still change. That's yet to be decided. But it wouldn't be Rust without unique pointers.
E.g. the following is almost exactly identical to `~T`
#[unsafe_no_drop_flag]
struct Uniq<T> { priv ptr: *mut T }
impl<T> Uniq<T> {
fn new(value: T) -> Uniq<T> {
unsafe {
let ptr = malloc(size_of::<T>()) as *mut T;
if ptr.is_null() { fail!("malloc failed"); }
move_val_init(&mut *ptr, value);
Uniq { ptr: ptr }
}
}
fn borrow<'a>(&'a self) -> &'a T {
unsafe {&*self.ptr}
}
fn borrow_mut<'a>(&'a mut self) -> &'a mut T {
unsafe {&mut *self.ptr}
}
fn move(mut self) -> T {
unsafe {
let v = ptr::read_ptr(self.ptr as *T);
free(self.ptr);
self.ptr = 0;
v
}
}
}
#[unsafe_destructor]
impl<T> Drop for Uniq<T> {
fn drop(&mut self) {
unsafe {
// this will free the pointer and run the
// destructor of the inner type
replace(self, transmute(0)).move();
}
}
}
1. The (yet-ongoing) removal of managed pointers, leaving us with one fewer pointer type. Final tally of built-in pointer types: unique pointers, mutable references, and immutable references.
2. The dead code detection pass (https://github.com/mozilla/rust/pull/10477), contributed by a student of the University of Virginia's Rust-based systems programming class (http://rust-class.org/pages/using-rust-for-an-undergraduate-...).
3. The `Any` trait, giving us on-demand dynamic typing (https://github.com/mozilla/rust/pull/9967).
4. The clean abstraction of green threads and native threads out into their own libraries (https://mail.mozilla.org/pipermail/rust-dev/2013-December/00...) such that any library that makes use of the stdlib will work regardless of which strategy the user selects.
We're not quite in the home stretch yet, but there are very few hard blockers left on 1.0. Here's the list that I can think of:
1. Dynamically-sized types (http://smallcultfollowing.com/babysteps/blog/2014/01/05/dst-...)
2. The extension of rvalue lifetimes (http://smallcultfollowing.com/babysteps/blog/2014/01/09/rval...)
3. Struct single (note that's single) inheritance (http://smallcultfollowing.com/babysteps/blog/2013/10/24/sing...)
4. Niceties and sugar to support custom smart pointer types to complete the excision of managed pointers
As far as I know, the devs are still aiming for a 1.0 release in 2014. The 1.0 release will not necessarily mean that the language is done evolving or ready for production use, but it will mean that the developers will begin honoring language-level and library-level backwards compatibility. I would expect at least two more unstable point releases (i.e. 0.10 and 0.11) before a 1.0 release occurs.