daily pastebin goal
6%
SHARE
TWEET

Untitled

a guest Dec 15th, 2018 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #[derive(Default)]
  2. struct Message {
  3.     e: Option<*mut u8>
  4. }
  5.  
  6. trait Owner {
  7.     type Message: Default;
  8.     fn produce_message(&self) -> Self::Message {
  9.         Default::default()
  10.     }
  11. }
  12.  
  13. struct You;
  14. struct Me;
  15.  
  16. #[derive(Default)]
  17. struct YourMessage(Message);
  18.  
  19. #[derive(Default)]
  20. struct MyMessage(Message);
  21.  
  22. impl Owner for You { type Message = YourMessage; }
  23. impl Owner for Me  { type Message = MyMessage; }
  24.  
  25. impl Drop for YourMessage {
  26.     fn drop(&mut self) {
  27.         println!("drop YourMessage");
  28.         println!("free(self.0.e)");
  29.     }
  30. }
  31.  
  32. impl Drop for MyMessage {
  33.     fn drop(&mut self) {
  34.         println!("drop MyMessage");
  35.         println!("free_magic(self.0.e)");
  36.     }
  37. }
  38.  
  39. fn main() {
  40.     let y = You;
  41.     y.produce_message();
  42.    
  43.     let m = Me;
  44.     m.produce_message();
  45.     m.produce_message();
  46. }
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
 
Top