- println! 打印信息用 {:#?} 打印出来的东西更加具有可读性,e.g.
#[derive(Debug)]
struct Rectangle {
width: u32,
height: u32,
}
fn main() {
let rect = Rectangle { width: 30, height: 50 };
println!("Rectangle: {:#?}", rect);
}
打印的内容:
Rectangle: Rectangle {
width: 30,
height: 50,
}
- 函数返回自定义错误信息
pub fn parse( ... ) -> io::Result<()> {
if something {
return Err(io::Error::new(io::ErrorKind::InvalidData,
format!("Error header")));
}
Ok(())
}