mozilla/rust — pull request #8014 by kbsletten (2013-07-23 23:10:52+00:00)
Title: Helpers for mutating non-copyable types

Because it is not possible to 'un-move' moved values, certain legal operations cannot be performed. This patch uses unsafe code to enable these operations on non-copyable types.

This adds support for 3 types of assignments:
```rust
x = func(x)
x = comb(x, y)
(x, y) = split(x)
```

The reason I want to add these things is for code like the following:
```rust
use std::util::{pack, unpack}

enum OwnList {
OwnCons(T, ~OwnCons),
OwnNil()
}

impl OwnList {
fn push(&mut self, item: T) {
do pack(self, item) |l, i| {
OwnCons(i, ~l)
}
}
fn pop(&mut self) -> Option {
do unpack(self) |l| {
match l {
OwnCons(item, next) => (*next, Some(item)),
OwnNil() => (OwnNil, None)
}
}
}
}
```