-
-
Save RandyMcMillan/048dc8e5613d0e7337a033ce4832f776 to your computer and use it in GitHub Desktop.
get_matching_enum.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#[allow(dead_code)] | |
enum Point { | |
Nothing, | |
TuplePoint(i32, i32), | |
StructPoint { | |
x: i32, | |
y: i32 | |
} | |
} | |
fn get_point(n: u8) -> Point { | |
match n { | |
1 => Point::TuplePoint(-1, 1), | |
2 => Point::StructPoint { | |
x: -1, | |
y: 1 | |
}, | |
_ => Point::Nothing | |
} | |
} | |
fn main() { | |
let p = get_point(2); | |
match p { | |
Point::Nothing => println!("no point"), | |
Point::TuplePoint(x, y) => println!("x is {} and y is {}", x, y), | |
//Point::StructPoint {x, y} => println!("x is {} and y is {}", x, y), | |
//#[allow(unreachable_patterns)] | |
_ => {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gh gist view 048dc8e5613d0e7337a033ce4832f776