[rust-dev] Passing arguments bu reference

Steve Klabnik steve at steveklabnik.com
Sun Jun 1 02:18:08 PDT 2014


one of the recent changes with box is that it does placement new. So
generally, this is bad:

fn foo(x: int) -> Box<int> {
   box (x + 1)
}

let y = foo(5);

Because it forces your caller to use a Box. Instead...

fn foo(x: int) -> int {
   x + 1
}

Because then your caller can choose:

let y = foo(5);

for a copy, and

let y = box foo(5);

for a boxed value. Or, in the future....

let y = box(GC) foo(5);

At least, that's my current understanding.


More information about the Rust-dev mailing list