From 0c7ce803849779af2ac6a2d3df401f5dafd57323 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 26 Apr 2023 16:20:23 +0200 Subject: [PATCH] Fix missing defmt impl. --- src/structs.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/structs.rs b/src/structs.rs index 6d5d31b0..f54ec7fc 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -115,7 +115,6 @@ impl SdpcmHeader { } #[derive(Debug, Clone, Copy)] -// #[cfg_attr(feature = "defmt", derive(defmt::Format))] #[repr(C, packed(2))] pub struct CdcHeader { pub cmd: u32, @@ -126,6 +125,25 @@ pub struct CdcHeader { } impl_bytes!(CdcHeader); +#[cfg(feature = "defmt")] +impl defmt::Format for CdcHeader { + fn format(&self, fmt: defmt::Formatter) { + fn copy(t: T) -> T { + t + } + + defmt::write!( + fmt, + "CdcHeader{{cmd: {=u32:08x}, len: {=u32:08x}, flags: {=u16:04x}, id: {=u16:04x}, status: {=u32:08x}}}", + copy(self.cmd), + copy(self.len), + copy(self.flags), + copy(self.id), + copy(self.status), + ) + } +} + impl CdcHeader { pub fn parse(packet: &mut [u8]) -> Option<(&mut Self, &mut [u8])> { if packet.len() < Self::SIZE {