Structs
A struct is a named group of typed fields. A literal provides every field in any order. Spread update starts from an existing value, then replaces the named fields that follow.
Field assignment requires a mutable root. Struct patterns mirror the declaration and may name, refine, or ignore fields.
struct Point {
x: int,
y: int,
}
fn main() {
let origin = Point { x: 0, y: 2 }
let moved = Point { ...origin, x: 3 }
println("${moved.x},${moved.y}")
}
Examples use the moon toolchain version shown beside each result.
Output & diagnostics
Expected: 3,2
Ctrl/⌘+Enter runs the current lesson.