(Just to keep everybody in the loop.) These will replace object
destructors in the future (and I'll start phasing those out as soon as
someone does a checkpoint, so that we can start using resources in the
compiler). The syntax is:

resource file_descriptor(int fd) {
    libc::close(fd);
}

You then get a function file_descriptor of one int argument, which
will return a non-copyable value of type file_descriptor (which is
nominal). When such a value is dropped, its destructor body is ran,
with the variable fd bound to the wrapped int. Resource values can be
dereferenced with *, like boxes, so this logs the fd:

auto my_fd <- file_descriptor(0);
log *my_fd;

I've only tested minimally, and there are some rough edges in move
semantics that might still break some use cases.
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to