SHARE
TWEET

Untitled

a guest Oct 16th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Foo;
  2.  
  3. impl Foo {
  4.     fn cleanup (self: &'_ mut Self)
  5.     {
  6.         panic!("Foo::cleanup({:p})", self);
  7.     }
  8. }
  9.  
  10. struct Struct {
  11.     foo: Foo,
  12. }
  13.  
  14. impl Drop for Struct {
  15.     fn drop (self: &'_ mut Self)
  16.     {
  17.         use ::std::panic;
  18.         let mut foo = panic::AssertUnwindSafe(&mut self.foo);
  19.         match panic::catch_unwind(move || {
  20.             foo.cleanup();
  21.         })
  22.         {
  23.             | Ok(()) => {},
  24.  
  25.             | Err(err) => {
  26.                 eprintln!("{:p}.foo.cleanup() panicked ({err_msg})", self,
  27.                     err_msg = if let Some(s) = err.downcast_ref::<String>() {
  28.                         s as &dyn ::core::fmt::Display
  29.                     } else {
  30.                         &""
  31.                     },
  32.                 );
  33.             },
  34.         }
  35.     }
  36. }
  37.  
  38. fn main ()
  39. {
  40.     drop(Struct { foo: Foo, });
  41.     println!("Program keeps going");
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top