trait

Pointer formatting

Pointer formatting is useful for local diagnostics, but address text varies between runs and must not be used as a stable identifier. Avoid exposing addresses in public logs. Expected stdout (not executed): true Common mistake: Expecting a fixed address or dereferencing a raw pointer to format it.

Formal Syntax & Structure

rust syntaxrust
{:p}

Working Example

Example Snippetrust
fn main() {    let n = 8;    let p = &n as *const i32;    let text = format!("{:p}", p);    println!("{}", text.starts_with("0x"));}
Rust Reference