Skip to content

Instantly share code, notes, and snippets.

@justanotherdot
Created January 26, 2021 05:29
Show Gist options
  • Save justanotherdot/c523094f240e5fa7871749369ef5ae34 to your computer and use it in GitHub Desktop.
Save justanotherdot/c523094f240e5fa7871749369ef5ae34 to your computer and use it in GitHub Desktop.
#[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