Created
January 26, 2021 05:29
-
-
Save justanotherdot/c523094f240e5fa7871749369ef5ae34 to your computer and use it in GitHub Desktop.
This file contains 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
#[derive(Debug)] | |
struct Resource(i32); | |
impl Drop for Resource { | |
fn drop(&mut self) { | |
println!("goodbye from {}", self.0); | |
} | |
} | |
enum Error { | |
Foo | |
} | |
impl Error { | |
pub fn exit_code(self) -> i32 { | |
match self { | |
Error::Foo => 114, | |
} | |
} | |
} | |
fn go() -> Result<(), Error> { | |
let _x = Resource(0); | |
return Err(Error::Foo); | |
} | |
fn main() { | |
go().unwrap_or_else(|e| { | |
println!("about to terminate the process"); | |
std::process::exit(e.exit_code()); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment