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 | |
8 | mod alloc_; |
9 | mod array; |
10 | mod cell; |
11 | #[cfg (feature = "ip_in_core" )] |
12 | mod net; |
13 | mod num; |
14 | mod ops; |
15 | mod panic; |
16 | mod ptr; |
17 | mod slice; |
18 | |
19 | use super::*; |
20 | use crate::export; |
21 | |
22 | impl<T> Format for Option<T> |
23 | where |
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: &T) => { |
38 | export::u8(&1); |
39 | export::istr(&T::_format_tag()); |
40 | x._format_data() |
41 | } |
42 | } |
43 | } |
44 | } |
45 | |
46 | impl<T, E> Format for Result<T, E> |
47 | where |
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: &E) => { |
62 | export::u8(&0); |
63 | export::istr(&E::_format_tag()); |
64 | e._format_data() |
65 | } |
66 | Ok(x: &T) => { |
67 | export::u8(&1); |
68 | export::istr(&T::_format_tag()); |
69 | x._format_data() |
70 | } |
71 | } |
72 | } |
73 | } |
74 | |
75 | impl<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 | |
87 | impl 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 | |
101 | impl 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 | |
112 | impl<A, B> Format for core::iter::Zip<A, B> |
113 | where |
114 | A: Format, |
115 | B: Format, |
116 | { |
117 | fn format(&self, fmt: Formatter) { |
118 | crate::write!(fmt, "Zip(..)" ) |
119 | } |
120 | } |
121 | |