E0213: Struct pattern not struct
| Code | Category | Stability |
|---|---|---|
E0213 | Semantic | Permanent |
Explanation
A struct pattern (preview feature struct_patterns) destructures a value whose type is not a struct. let T { ... } = e; names the fields of a struct type, so the initializer must have exactly the struct type the pattern's head names.
Likely cause
The pattern head names a type that is not a struct, or the initializer has a different type than the head. Name the initializer's own struct type in the pattern head, or bind the value with an ordinary let.
Examples
Destructure an integer
Requires --preview struct_patterns.
const N = i32;
fn main() -> i32 {
let N { value } = 5;
value
}
Destructure a struct value
Requires --preview struct_patterns.
struct Point { x: i32, y: i32 }
fn main() -> i32 {
let Point { x, y } = Point { x: 40, y: 2 };
x + y
}