更多 trait
已经派生了 Debug trait。如果再实现更多 trait,会大有帮助。
use core::fmt::{self, Write};
impl Write for Uart {
fn write_str(&mut self, s: &str) -> fmt::Result {
for c in s.as_bytes() {
self.write_byte(*c);
}
Ok(())
}
}
// SAFETY: `Uart` just contains a pointer to device memory, which can be
// accessed from any context.
unsafe impl Send for Uart {}
- 通过实现
Write,我们可以将write!和writeln!宏与Uart类型搭配使用。 - 在 QEMU 中,使用
src/bare-metal/aps/examples目录下的make qemu_minimal运行该示例。