Ruta graveolens  ·  notes from a language experiment  ·  cultivated since 2025

E0213: Struct pattern not struct

CodeCategoryStability
E0213SemanticPermanent

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
}

References