E0423: Field access on non struct
| Code | Category | Stability |
|---|---|---|
E0423 | Struct and enum | Permanent |
Explanation
A field-based operation was applied to a non-struct type. Both .field access and @offset_of(Type, field) require the value or type being inspected to be a struct.
Likely cause
The expression before .field has an unexpected scalar, enum, array, or other non-struct type, or the first argument to @offset_of is not a struct type. Check the relevant value or type and name fields only on a struct.
Examples
Field access on an integer
fn main() -> i32 {
let value: i32 = 42;
value.answer
}
Access a field on a struct
struct Answer { value: i32 }
fn main() -> i32 {
let answer = Answer { value: 42 };
answer.value
}