[rust-dev] No more obj { drop {} } -- use resources!

Marijn Haverbeke marijnh at gmail.com
Fri Jul 29 05:12:13 PDT 2011

As was decided when resources were introduced (I hope most of you were
informed), we wanted to drop support for object destructors. Resources
are now mostly useable -- though if you want to store or pass them
somewhere, you have to box them immediately on creation until we get
our move semantics worked out, or you'll get weird errors about
copying noncopyable types—or even code that silently does the wrong

resource my_cleanup(x: my_pointer_type) {

fn test() {
    // This is safe, cleans up the pointer at end of block
        let x = my_cleanup(my_mk_pointer());
        do_stuff(*x); // Pass raw pointer

    // This is safe, will clean up when refcount hits zero

    // Don't do this (yet)

More information about the Rust-dev mailing list