その他のトレイト
Debug トレイトは derive しました。さらにいくつかのトレイトも実装すると便利です。
// 著作権 2023 Google LLC // SPDX-License-Identifier: Apache-2.0 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を実装すると、Uart型でwrite!マクロとwriteln!マクロを使えるようになります。 -
Sendは自動トレイトですが、ポインタには実装されていないため、自動的には実装されません。