Field Access Expressions
A field access expression accesses a field of a struct.
field_access = expression "." IDENT ;
The expression before the dot must have a struct type.
The identifier must be a valid field name for that struct type.
The type of a field access expression is the type of the accessed field.
struct Point {
x: i32,
y: i32,
}
fn main() -> i32 {
let p = Point { x: 10, y: 32 };
p.x + p.y // 42
}
Field Assignment
For mutable struct values, fields can be assigned.
struct Point {
x: i32,
y: i32,
}
fn main() -> i32 {
let mut p = Point { x: 0, y: 0 };
p.x = 20;
p.y = 22;
p.x + p.y // 42
}