Field access expressions
FieldAccessExpression = ExpressionWithoutBlock , "." , Identifier
;
A field access expression evaluates the operand and produces the value of the named field.
local-field-access preview feature
Warning
Requires
local-field-accesspreview feature enabled.
Accessing a field of a local variable at runtime
requires the local-field-access preview feature to be enabled:
struct Point { x: u8, y: u8 }
global P: Point;
fn main() {
let p = P;
let x: u8 = p.x; // requires `local-field-access`
}
The preview feature is not required when the field access operand is a global variable or when it appears inside a const item, as those forms are evaluated without needing to materialise the aggregate in a local:
struct Point { x: u8, y: u8 }
global P: Point;
const ORIGIN_X: u8 = {
let p: Point = Point { x: 0, y: 0 };
yield p.x; // ok, evaluated at compile time
};
fn main() {
let x: u8 = P.x; // ok, field access on a global
}