Last active
November 18, 2022 12:35
-
-
Save ochaloup/ceaf3827dea9f6a51fa9ecac48876652 to your computer and use it in GitHub Desktop.
Simple attempt to fetch understanding on match/return of error
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
| // 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