traitهای بیشتر
ما ویژگی Debug را استخراج کردیم. اجرای چند ویژگی دیگر نیز مفید خواهد بود.
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 با
make qemu_minimalدر زیرsrc/bare-metal/aps/examplesاجرا کنید.