Skip to content

Instantly share code, notes, and snippets.

@triplepoint
Created January 2, 2016 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triplepoint/ff2ab81f5f89826d35b7 to your computer and use it in GitHub Desktop.
Save triplepoint/ff2ab81f5f89826d35b7 to your computer and use it in GitHub Desktop.
Short rust pattern-matching demonstration.
fn main() {
//let some_value: Result<i32, &'static str> = Ok(12);
//let some_value: Result<i32, &'static str> = Err("METAL!");
let some_value: Result<i32, &'static str> = Err("There was an error");
match some_value {
Ok(value) => println!("got a value: {}", value),
Err("METAL!") => println!("a specific metal error occured"),
Err(x) => println!("an unknown error occurred: {}", x),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment