defmt/impls/core_/
mod.rs

1//! Some of these objects don't expose enough to accurately report their debug state. In this case
2//! we show as much state as we can. Users can always use `Debug2Format` to get more information,
3//! at the cost of bringing core::fmt into the firmware and doing the layout work on device.
4//!
5//! We generally keep the type parameter trait bounds in case it becomes possible to use this
6//! later, without making a backwards-incompatible change.
7
8mod alloc_;
9mod array;
10mod cell;
11#[cfg(feature = "ip_in_core")]
12mod net;
13mod num;
14mod ops;
15mod panic;
16mod ptr;
17mod slice;
18
19use super::*;
20use crate::export;
21
22impl<T> Format for Option<T>
23where
24    T: Format,
25{
26    default_format!();
27
28    #[inline]
29    fn _format_tag() -> Str {
30        internp!("None|Some({=?})")
31    }
32
33    #[inline]
34    fn _format_data(&self) {
35        match self {
36            None => export::u8(&0),
37            Some(x) => {
38                export::u8(&1);
39                export::istr(&T::_format_tag());
40                x._format_data()
41            }
42        }
43    }
44}
45
46impl<T, E> Format for Result<T, E>
47where
48    T: Format,
49    E: Format,
50{
51    default_format!();
52
53    #[inline]
54    fn _format_tag() -> Str {
55        internp!("Err({=?})|Ok({=?})")
56    }
57
58    #[inline]
59    fn _format_data(&self) {
60        match self {
61            Err(e) => {
62                export::u8(&0);
63                export::istr(&E::_format_tag());
64                e._format_data()
65            }
66            Ok(x) => {
67                export::u8(&1);
68                export::istr(&T::_format_tag());
69                x._format_data()
70            }
71        }
72    }
73}
74
75impl<T> Format for core::marker::PhantomData<T> {
76    default_format!();
77
78    #[inline]
79    fn _format_tag() -> Str {
80        internp!("PhantomData")
81    }
82
83    #[inline]
84    fn _format_data(&self) {}
85}
86
87impl Format for core::convert::Infallible {
88    default_format!();
89
90    #[inline]
91    fn _format_tag() -> Str {
92        unreachable!();
93    }
94
95    #[inline]
96    fn _format_data(&self) {
97        unreachable!();
98    }
99}
100
101impl Format for core::time::Duration {
102    fn format(&self, fmt: Formatter) {
103        crate::write!(
104            fmt,
105            "Duration {{ secs: {=u64}, nanos: {=u32} }}",
106            self.as_secs(),
107            self.subsec_nanos(),
108        )
109    }
110}
111
112impl<A, B> Format for core::iter::Zip<A, B>
113where
114    A: Format,
115    B: Format,
116{
117    fn format(&self, fmt: Formatter) {
118        crate::write!(fmt, "Zip(..)")
119    }
120}