The docs explain how you can use ..
when instantiating structs:
struct Point3d {
x: i32,
y: i32,
z: i32,
}
let mut point = Point3d { x: 0, y: 0, z: 0 };
point = Point3d { y: 1, .. point };
Why doesn't this operator work with structs of a different type?
struct Point3d {
x: i32,
y: i32,
}
let mut p2 = Point2d { x: 0, y: 0 };
let p3 = Point3d { z: 0, .. p2};
This produces an error regarding p2
: expected struct `Point3d`, found struct `Point2d`
.
Could someone explain why this work? Seems like the compiler should be able to do this ...