rustlings/exercises/12_options/options3.rs
2024-02-01 16:29:59 -05:00

22 lines
533 B
Rust

// options3.rs
//
// Execute `rustlings hint options3` or use the `hint` watch subcommand for a
// hint.
struct Point {
x: i32,
y: i32,
}
fn main() {
let y: Option<Point> = Some(Point { x: 100, y: 200 });
match y { // &y can also be used here to borrow instead of moving ownership of y to the match expression
// ref is used during pattern matching.
Some(ref p) => println!("Co-ordinates are {},{} ", p.x, p.y),
_ => panic!("no match!"),
}
y; // Fix without deleting this line.
}