Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. struct Test {
  2. x : i32,
  3. }
  4.  
  5. impl Test {
  6. fn new() -> Box<Self> {
  7. let t = Test {x : 100};
  8. let bt = Box::new(t);
  9. println!("Address of t when creating it: {:p}", &*bt);
  10. bt
  11. }
  12.  
  13. fn print_addr(&self) {
  14. println!("My address: {:p}", self as *const Test);
  15. }
  16. }
  17.  
  18. fn main() {
  19. let test = Test::new();
  20. test.print_addr();
  21. let test2 = test;
  22. test2.print_addr();
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement