Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #![allow(unused)]
  2. struct PrintOnDrop(&'static str);
  3.  
  4. impl Drop for PrintOnDrop {
  5. fn drop(&mut self) {
  6. println!("{}", self.0);
  7. }
  8. }
  9.  
  10. fn main() {
  11. macro_rules! guard {
  12. ($label: expr) => {
  13. let _guard = PrintOnDrop($label);
  14. }
  15. }
  16.  
  17. guard!("Declared first!");
  18. let _guard = PrintOnDrop("Declared second!");
  19. guard!("Declared third!");
  20. let _guard = PrintOnDrop("Declared fourth!");
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement