You shouldn't return a Box<T> unless you have to: box does placement
new, so by not doing it yourself, you give them options:

struct Point {
    x: int,
    y: int,
}

impl Point {
    fn bad_new() -> Box<Point> {
        box Point { x: 1, y: 1 }
    }

    fn good_new() -> Point {
        Point { x: 1, y: 1 }
    }
}

fn main() {
   let x = Point::bad_new(); // this _must_ be Box<Point>, and nothing else

   let y = box Point::good_new(); // this is a Box<Point>, with no copy, but...

   let z = box(std::gc::Gc) Point::good_new(); // this is a Gc<Point>,
with no copy.
}
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to