Guest User

Untitled

a guest
Jan 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. fn main() {
  2. Io {
  3. out: "",
  4. err: "",
  5. }.out = "You can overload the assignment operator in Rust!";
  6. println!("{:p}", &std);
  7. std.out = "No, really! Check out the output of this program!";
  8. println!("{:p}", &std);
  9. std.err = "Warning: restrictions apply";
  10. }
  11.  
  12.  
  13. #[allow(non_upper_case_globals)]
  14. const std : Io = Io {
  15. out: "",
  16. err: "",
  17. };
  18.  
  19. struct Io {
  20. out: &'static str,
  21. err: &'static str,
  22. }
  23.  
  24. impl Drop for Io {
  25. fn drop(&mut self) {
  26. println!("{}", self.out);
  27. eprintln!("{}", self.err);
  28. }
  29. }
Add Comment
Please, Sign In to add comment