With this code:
struct Point {
x: f64,
y: f64,
}
struct Rectangle {
p1: Point,
p2: Point,
}
impl Rectangle {
pub fn new(x1: f64, y1: f64, x2: f64, y2: f64) -> Rectangle {
let r = Rectangle {
p1: Point { x: x1, y: y1 },
p2: Point { x: x2, y: y2 },
};
// some code where r is used
r
}
}
let rectangle = Rectangle::new(0.0, 0.0, 10.0, 10.0);
From a memory point of view, is rectangle the same instance as r, or is it a copy of r?
Do I have to explicitly return by reference (something like &r)?
I have to create millions of rectangles, and I don't want there to be useless copies.