Skip to content

Instantly share code, notes, and snippets.

@ochaloup
Last active November 18, 2022 12:35
Show Gist options
  • Select an option

  • Save ochaloup/ceaf3827dea9f6a51fa9ecac48876652 to your computer and use it in GitHub Desktop.

Select an option

Save ochaloup/ceaf3827dea9f6a51fa9ecac48876652 to your computer and use it in GitHub Desktop.
Simple attempt to fetch understanding on match/return of error
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ceaf3827dea9f6a51fa9ecac48876652
#![allow(unused)]
fn main() {
fn say_hello(str: &str) -> Result<(), &str> {
match str {
"abc" => println!("this is abc!"),
"error" => return Err("this is error!"),
something_else => println!("{}", something_else)
}
Ok(())
}
say_hello("abc");
say_hello("error").unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment