Closed DylanSp closed 1 year ago
Sources:
Example enum:
enum Message {
Quit,
Move { x: i32, y: i32 },
Write(String),
ChangeColor(i32, i32, i32),
}
Move
in the example.Write
is effectively a 1-tuple, ChangeColor
is effectively a 3-tuplePattern matching can destructure using field names. Example code:
match msg {
Message::Move { x, y } => {
println!("Move in the x direction {x} and in the y direction {y}");
}
// omitted - Quit, Write, ChangeColor cases
}
Type definitions:
Pattern matching:
Issues include - can a struct be one case of a sum type?
Look what Rust does for inspiration.