Guest User

Untitled

a guest
Oct 17th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. extern crate nodrop; // 0.1.12
  2.  
  3. use nodrop::NoDrop;
  4. use std::ops::Drop;
  5.  
  6. struct Precious;
  7. fn cleanup(_: Precious) { println!("cleaned up"); }
  8.  
  9. struct Abc(NoDrop<Precious>);
  10. struct AbcDroppable(Option<Precious>);
  11.  
  12. impl Abc {
  13. fn make_droppable(self) -> AbcDroppable {
  14. AbcDroppable(Some(self.0.into_inner()))
  15. }
  16. }
  17.  
  18.  
  19. impl Drop for AbcDroppable {
  20. fn drop(&mut self) {
  21. cleanup(self.0.take().unwrap()) // Should abort or something? Do we want to panic in drop?
  22. }
  23. }
  24.  
  25.  
  26. fn main() {
  27. let abc = Abc(NoDrop::new(Precious)); // init our struct.
  28.  
  29. abc.make_droppable();
  30. }
Add Comment
Please, Sign In to add comment