diff --git a/src/iterators/drain.rs b/src/iterators/drain.rs index 07f5e546..7fef4aaa 100644 --- a/src/iterators/drain.rs +++ b/src/iterators/drain.rs @@ -1,3 +1,9 @@ +#[cfg(feature = "defmt")] +use defmt::{ + Format as DeFormat, + Formatter as DeFormatter, + write as dewrite +}; use { super::super::{ SmallVec, @@ -246,3 +252,12 @@ impl Debug for Drain<'_, Item f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() } } + +#[cfg(feature = "defmt")] +impl DeFormat + for Drain<'_, Item, INLINE, Heap> +{ + fn format(&self, fmt: DeFormatter) { + dewrite!(fmt, "Drain({=[?]})", self.iter.as_slice()); + } +} diff --git a/src/iterators/extractif.rs b/src/iterators/extractif.rs index e0ee1b5f..38066b51 100644 --- a/src/iterators/extractif.rs +++ b/src/iterators/extractif.rs @@ -1,3 +1,9 @@ +#[cfg(feature = "defmt")] +use defmt::{ + Format as DeFormat, + Formatter as DeFormatter, + write as dewrite +}; use { super::super::{ SmallVec, @@ -51,6 +57,18 @@ where } } +#[cfg(feature = "defmt")] +impl DeFormat + for ExtractIf<'_, Item, INLINE, F, Heap> +where + F: FnMut(&mut Item) -> bool, + Item: DeFormat +{ + fn format(&self, fmt: DeFormatter) { + dewrite!(fmt, "ExtractIf({=[?]})", self.vec.as_ref()); + } +} + impl Iterator for ExtractIf<'_, Item, INLINE, F, Heap> where F: FnMut(&mut Item) -> bool diff --git a/src/iterators/intoiter.rs b/src/iterators/intoiter.rs index ec08ec90..b02baa91 100644 --- a/src/iterators/intoiter.rs +++ b/src/iterators/intoiter.rs @@ -1,3 +1,9 @@ +#[cfg(feature = "defmt")] +use defmt::{ + Format as DeFormat, + Formatter as DeFormatter, + write as dewrite +}; use { super::super::{ DropDealloc, @@ -223,3 +229,12 @@ impl Debug for IntoIter DeFormat + for IntoIter +{ + fn format(&self, fmt: DeFormatter) { + dewrite!(fmt, "IntoIter({=[?]})", self.as_ref()); + } +} diff --git a/src/iterators/splice.rs b/src/iterators/splice.rs index a08086dd..5d0605e6 100644 --- a/src/iterators/splice.rs +++ b/src/iterators/splice.rs @@ -1,3 +1,9 @@ +#[cfg(feature = "defmt")] +use defmt::{ + Format as DeFormat, + Formatter as DeFormatter, + write as dewrite +}; use { super::{ super::{ @@ -43,6 +49,17 @@ where } } +#[cfg(feature = "defmt")] +impl<'valid, I, const INLINE: usize, Heap: Allocator> DeFormat for Splice<'valid, I, INLINE, Heap> +where + I: Iterator + 'valid, + ::Item: DeFormat +{ + fn format(&self, fmt: DeFormatter) { + dewrite!(fmt, "Splice({})", self.drain); + } +} + impl Iterator for Splice<'_, I, INLINE, Heap> { type Item = I::Item; diff --git a/src/locatedlength.rs b/src/locatedlength.rs index fc833347..29022294 100644 --- a/src/locatedlength.rs +++ b/src/locatedlength.rs @@ -1,4 +1,17 @@ -use core::marker::PhantomData; +use core::{ + fmt::{ + Debug, + Formatter, + Result as Format + }, + marker::PhantomData +}; +#[cfg(feature = "defmt")] +use defmt::{ + Format as DeFormat, + Formatter as DeFormatter, + write as dewrite +}; /// Vec guarantees that its length is always less than [`isize::MAX`] in /// *bytes*. @@ -23,6 +36,29 @@ impl Clone for LocatedLength { impl Copy for LocatedLength {} +impl Debug for LocatedLength { + fn fmt(&self, f: &mut Formatter<'_>) -> Format { + let (length, on_heap) = self.parts(); + f.debug_struct("LocatedLength") + .field("length", &length) + .field("on_heap", &on_heap) + .finish() + } +} + +#[cfg(feature = "defmt")] +impl DeFormat for LocatedLength { + fn format(&self, fmt: DeFormatter) { + let (length, on_heap) = self.parts(); + dewrite!( + fmt, + "LocatedLength {{ length: {=usize}, on_heap: {=bool} }}", + length, + on_heap + ); + } +} + #[allow(clippy::len_without_is_empty)] impl LocatedLength { const MAX_LEN: usize = usize::MAX >> Self::SHIFT; diff --git a/src/rawsmallvec.rs b/src/rawsmallvec.rs index 7c8d8f8e..9b0d39b6 100644 --- a/src/rawsmallvec.rs +++ b/src/rawsmallvec.rs @@ -1,3 +1,9 @@ +#[cfg(feature = "defmt")] +use defmt::{ + Format as DeFormat, + Formatter as DeFormatter, + write as dewrite +}; use { super::{ allocator::Allocator, @@ -6,6 +12,11 @@ use { }, core::{ alloc::Layout, + fmt::{ + Debug, + Formatter, + Result as Format + }, mem::{ ManuallyDrop, MaybeUninit @@ -23,6 +34,21 @@ pub union RawSmallVec { pub heap: (NonNull, usize) } +// The active member is tracked by `LocatedLength`, not by the union itself, so +// neither member can be read safely here. +impl Debug for RawSmallVec { + fn fmt(&self, f: &mut Formatter<'_>) -> Format { + f.debug_struct("RawSmallVec").finish_non_exhaustive() + } +} + +#[cfg(feature = "defmt")] +impl DeFormat for RawSmallVec { + fn format(&self, fmt: DeFormatter) { + dewrite!(fmt, "RawSmallVec {{ .. }}"); + } +} + impl RawSmallVec { pub const INLINE_CAP: usize = if Self::IS_ZST { usize::MAX } else { INLINE }; const IS_ZST: bool = size_of::() == 0;