[−][src]Function tao_of_rust::ch02::generics_trait::impl_debug_trait
pub fn impl_debug_trait()
impl Debug trait示例
Basic usage:
use std::fmt::*; struct Point { x: i32, y: i32, } // Debug trait中定义了fmt方法 impl Debug for Point { fn fmt(&self, f: &mut Formatter) -> Result { // 使用编译器内置的write!宏来实现 write!(f, "Point {{ x: {}, y: {} }}", self.x, self.y) } } let origin = Point { x: 0, y: 0 }; println!("The origin is: {:?}", origin);Run