Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Test {
- x : i32,
- }
- impl Test {
- fn new() -> Box<Self> {
- let t = Test {x : 100};
- let bt = Box::new(t);
- println!("Address of t when creating it: {:p}", &*bt);
- bt
- }
- fn print_addr(&self) {
- println!("My address: {:p}", self as *const Test);
- }
- }
- fn main() {
- let test = Test::new();
- test.print_addr();
- let test2 = test;
- test2.print_addr();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement