- std::ptr::addr_of
- addr_of
Compare memory address (pointer)
- Another way to show that different pieces of strings are located in different places in the memory.
examples/strings/compare-memory-address/src/main.rs
fn main() { let text_a = "Hello, world!"; let text_b = "Hello, world!"; println!("{}", text_a == text_b); println!( "{}", std::ptr::addr_of!(text_a) == std::ptr::addr_of!(text_b) ); println!("{:?}", &std::ptr::addr_of!(text_a)); println!("{:?}", &std::ptr::addr_of!(text_b)); println!(); let text_a = String::from("Hello, world!"); let text_b = String::from("Hello, world!"); println!("{}", text_a == text_b); println!( "{}", std::ptr::addr_of!(text_a) == std::ptr::addr_of!(text_b) ); println!("{:?}", &std::ptr::addr_of!(text_a)); println!("{:?}", &std::ptr::addr_of!(text_b)); }
true false 0x7ffddbd50e38 0x7ffddbd50e50