`impl<T> Format for {*const, *mut} T where T: Format + ?Sized`
This behaves like `std::fmt::Debug` by printing the address as hex.
-use crate as defmt;
use defmt_macros::internp;
-use crate::{Format, Formatter, Str};
+use crate::{self as defmt, Format, Formatter, Str};
impl Format for i8 {
fn format(&self, fmt: Formatter) {
@@ -468,3 +467,24 @@ impl Format for core::time::Duration {
)
}
}
+
+// Format raw pointer as hexadecimal
+//
+// First cast raw pointer to thin pointer, then to usize and finally format as hexadecimal.
+impl<T> Format for *const T
+where
+ T: Format + ?Sized,
+{
+ fn format(&self, fmt: Formatter) {
+ crate::write!(fmt, "{:x}", *self as *const () as usize);
+ }
+}
+
+impl<T> Format for *mut T
+where
+ T: Format + ?Sized,
+{
+ fn format(&self, fmt: Formatter) {
+ Format::format(&(*self as *const T), fmt)
+ }
+}
