Types that implement move semantics
If a type allocates memory, it is a good idea to implement move function, so that instances
can be passed around by value, leaving inert instances behind. This is chiefly used to defer
expressions are more ergonomic.
use std::collections::Vector;
fn do_something(v: Vector<i32>) {
// ...
v.free();
}
let foo: Vector<i32> = Vector::new();
defer foo.free(); // Clean up foo if function returns early
// ...
do_something(foo.move());
// will not lead to double free when this function returns.
Run this example