Advertisement
Guest User

Untitled

a guest
Jul 11th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. trait Y {}
  2.  
  3. struct X;
  4.  
  5. impl Drop for X {
  6. fn drop(&mut self) {
  7. println!("Dropping!");
  8. }
  9. }
  10.  
  11. impl Y for X {}
  12.  
  13. fn take_ownership(x: Box<dyn Y>) {
  14. println!("About to drop!");
  15. std::mem::drop(x);
  16. }
  17.  
  18. fn main() {
  19. let x: Box<dyn Y> = Box::new(X);
  20. take_ownership(x);
  21. println!("Should be dropped now");
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement