I have a struct:
struct Point {
x: u32,
y: u32,
}
I want to have two Point
s in two different variables. I want to declare them first and initialize later. It works fine with separate values:
let p0: Point;
let p1: Point;
p0 = Point { x: 1, y: 2 };
p1 = Point { x: 2, y: 3 };
I want to do the same but with an array:
let p: [Point; 2];
p[0] = Point { x: 1, y: 2 };
p[1] = Point { x: 2, y: 3 };
Doesn't work as I get a compilation error:
error[E0381]: use of possibly-uninitialized variable: `p`
--> src/main.rs:9:5
|
9 | p[0] = Point { x: 1, y: 2 };
| ^^^^ use of possibly-uninitialized `p`
Why does it behave differently for single variables and arrays? Can I do it without using Default::default()
?