In Rust, the Debug
trait allows you to format your types using the {:?}
formatter, making it easier to inspect and debug your code. Instead of manually implementing the Debug
trait for every struct, Rust provides the convenient #[derive(Debug)]
attribute to automatically generate a Debug
implementation.
For this challenge, you will work with structs that represent different types of data. Your task is to implement the Debug
trait using the derive
macro and demonstrate its functionality with sample structs.
Person
, Point
, Rectangle
).Debug
trait for each struct using #[derive(Debug)]
.#[derive(Debug)]
attribute for all structs.// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u8}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: u32, pub height: u32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u8,}#[derive(Debug)]pub struct Point { pub x: f64, pub y: f64, }#[derive(Debug)]pub struct Rectangle { pub width: usize, pub height: usize,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f64, pub y: f64,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: u32, pub height: u32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32}#[derive(Debug)]pub struct Point { pub x: f64, pub y: f64,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u8,}#[derive(Debug)]pub struct Point { pub x:f64, pub y: f64,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: i16, pub height: i16}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u8}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: u32, pub height: u32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u8}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: u32, pub height: u32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u8,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u8}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u8}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i8}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
#[derive(Debug)] // required by this formatting parameterpub struct Person { pub name: String, pub age: u8,}pub struct Point { pub x: f64, pub y: f64,}use std::fmt;impl fmt::Debug for Point { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { //使用默认的结构体格式化方法 debug_struct 来输出 f.debug_struct("Point") .field("x", &self.x) .field("y", &self.y) .finish() //Point { x: 5.0, y: -3.2 } //自定义格式化方法输出 //write!(f, "Point [{} {}]", self.x, self.y) // Point [5 -3.2] }}#[derive(Debug)]pub struct Rectangle { pub width: usize, pub height: usize,}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person {pub name :String, pub age: u32}#[derive(Debug)]pub struct Point {pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle {pub width: u32, pub height: u32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.#[derive(Debug)]pub struct Person { pub name: String, pub age: u16,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: u16, pub height: u16,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person {pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point {pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle {pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u16,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: u16, pub height: u16,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f64, pub y: f64,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u8,}#[derive(Debug)]pub struct Point { pub x: f64, pub y: f64,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
#[derive(Debug)]pub struct Person { pub name: String, pub age: usize,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: usize, pub height: usize,}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f64, pub y: f64,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f64, pub y: f64,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u8}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: u32, pub height: u32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: u32, pub height: u32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: u32, pub height: u32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name : String, pub age : u8}#[derive(Debug)]pub struct Point { pub x : f32, pub y : f32}#[derive(Debug)]pub struct Rectangle { pub width : u32, pub height : u32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width:i32, pub height:i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name :String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x :f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width:i32, pub height:i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u32}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: u32, pub height: u32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u32}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32}#[derive(Debug)]pub struct Rectangle { pub width: u32, pub height: u32}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f64, pub y: f64,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: u8,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name: String, pub age: i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
// 1. Complete the definitions of the structs Person, Point, and Rectangle.// have a look at the function below `debug_example` to get the fields of the structs.//// 2. Make sure you implement the Debug trait for each struct. using the derive attribute.#[derive(Debug)]pub struct Person { pub name : String, pub age : i32,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}
#[derive(Debug)]pub struct Person { pub name: String, pub age: u8,}#[derive(Debug)]pub struct Point { pub x: f32, pub y: f32,}#[derive(Debug)]pub struct Rectangle { pub width: i32, pub height: i32,}// Example functionpub fn debug_example() { let person = Person { name: "Alice".to_string(), age: 30, }; println!("{:?}", person); let point = Point { x: 5.0, y: -3.2 }; println!("{:?}", point); let rectangle = Rectangle { width: 10, height: 20, }; println!("{:?}", rectangle);}