diff options
Diffstat (limited to 'src/fmt.rs')
| -rw-r--r-- | src/fmt.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/fmt.rs b/src/fmt.rs index f8bb0a035..5730447b3 100644 --- a/src/fmt.rs +++ b/src/fmt.rs | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | #![allow(unused_macros)] | 2 | #![allow(unused_macros)] |
| 3 | 3 | ||
| 4 | use core::fmt::{Debug, Display, LowerHex}; | ||
| 5 | |||
| 4 | #[cfg(all(feature = "defmt", feature = "log"))] | 6 | #[cfg(all(feature = "defmt", feature = "log"))] |
| 5 | compile_error!("You may not enable both `defmt` and `log` features."); | 7 | compile_error!("You may not enable both `defmt` and `log` features."); |
| 6 | 8 | ||
| @@ -226,3 +228,30 @@ impl<T, E> Try for Result<T, E> { | |||
| 226 | self | 228 | self |
| 227 | } | 229 | } |
| 228 | } | 230 | } |
| 231 | |||
| 232 | pub struct Bytes<'a>(pub &'a [u8]); | ||
| 233 | |||
| 234 | impl<'a> Debug for Bytes<'a> { | ||
| 235 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| 236 | write!(f, "{:#02x?}", self.0) | ||
| 237 | } | ||
| 238 | } | ||
| 239 | |||
| 240 | impl<'a> Display for Bytes<'a> { | ||
| 241 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| 242 | write!(f, "{:#02x?}", self.0) | ||
| 243 | } | ||
| 244 | } | ||
| 245 | |||
| 246 | impl<'a> LowerHex for Bytes<'a> { | ||
| 247 | fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
| 248 | write!(f, "{:#02x?}", self.0) | ||
| 249 | } | ||
| 250 | } | ||
| 251 | |||
| 252 | #[cfg(feature = "defmt")] | ||
| 253 | impl<'a> defmt::Format for Bytes<'a> { | ||
| 254 | fn format(&self, fmt: defmt::Formatter) { | ||
| 255 | defmt::write!(fmt, "{:02x}", self.0) | ||
| 256 | } | ||
| 257 | } | ||
