More traits

We derived the Debug trait. It would be useful to implement a few more traits too.

  1. use core::fmt::{self, Write};
  2. impl Write for Uart {
  3.     fn write_str(&mut self, s: &str) -> fmt::Result {
  4.         for c in s.as_bytes() {
  5.             self.write_byte(*c);
  6.         }
  7.         Ok(())
  8.     }
  9. }
  10. // SAFETY: `Uart` just contains a pointer to device memory, which can be
  11. // accessed from any context.
  12. unsafe impl Send for Uart {}
  • Implementing Write lets us use the write! and writeln! macros with our Uart type.
  • Run the example in QEMU with make qemu_minimal under src/bare-metal/aps/examples.