Part of the “Rustober” series.
One of the Rust quirks is that when initializing a struct, the named fields can be in any order:
struct Point {
first: i32,
second: i32,
third: i32,
}
let p = Point { third: 1, second: 2, first: 3 };
In Swift, this is an error. However, looking at the rules for C initialization, it seems the C behavior is the same, called “designated initializer” and has been available since C99. Possibly, this also has to deal with Rust’s struct update syntax where you can initialize a struct based on another instance, in which case the set of field names would be incomplete, so their order does not really matter since they are named:
// Use values from p but change .third to 3
let p2 = Point {
third: 3,
..p
};