#[derive(Debug)] generates a debug formatter so a struct can be printed with {:?}.

Program

Play the program to print a point using its derived Debug output.

derive_debug.rs
#[derive(Debug)]
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let x = ;
    let y = 2;
    let p = Point { x, y };
    println!("{p:?}");
}
#[derive(Debug)]
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let x = ;
    let y = 2;
    let p = Point { x, y };
    println!("{p:?}");
}
#[derive(Debug)]
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let x = ;
    let y = 2;
    let p = Point { x, y };
    println!("{p:?}");
}
derive `#[derive(Debug)]` auto-generates trait code.
Debug The `Debug` trait enables developer-facing formatting.
{:?} `{:?}` prints the derived debug representation.