Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Created January 13, 2014 06:30
Embed
What would you like to do?
result in rust
fn foo(x: int) -> Result<int, ~str> {
if x == 5 {
Ok(5)
} else {
Err(~"x was not five")
}
}
fn main() {
match foo(5) {
Ok(num) => println!("Success! {:d}", num),
Err(msg) => println!("failure: {:s}", msg)
}
match foo(6) {
Ok(num) => println!("Success! {:d}", num),
Err(msg) => println!("failure: {:s}", msg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment