Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/iterators/drain.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#[cfg(feature = "defmt")]
use defmt::{
Format as DeFormat,
Formatter as DeFormatter,
write as dewrite
};
use {
super::super::{
SmallVec,
Expand Down Expand Up @@ -246,3 +252,12 @@ impl<Item: Debug, const INLINE: usize, Heap: Allocator> Debug for Drain<'_, Item
f.debug_tuple("Drain").field(&self.iter.as_slice()).finish()
}
}

#[cfg(feature = "defmt")]
impl<Item: DeFormat, const INLINE: usize, Heap: Allocator> DeFormat
for Drain<'_, Item, INLINE, Heap>
{
fn format(&self, fmt: DeFormatter) {
dewrite!(fmt, "Drain({=[?]})", self.iter.as_slice());
}
}
18 changes: 18 additions & 0 deletions src/iterators/extractif.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#[cfg(feature = "defmt")]
use defmt::{
Format as DeFormat,
Formatter as DeFormatter,
write as dewrite
};
use {
super::super::{
SmallVec,
Expand Down Expand Up @@ -51,6 +57,18 @@ where
}
}

#[cfg(feature = "defmt")]
impl<Item, const INLINE: usize, Heap: Allocator, F> 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<Item, F, const INLINE: usize, Heap: Allocator> Iterator
for ExtractIf<'_, Item, INLINE, F, Heap>
where F: FnMut(&mut Item) -> bool
Expand Down
15 changes: 15 additions & 0 deletions src/iterators/intoiter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#[cfg(feature = "defmt")]
use defmt::{
Format as DeFormat,
Formatter as DeFormatter,
write as dewrite
};
use {
super::super::{
DropDealloc,
Expand Down Expand Up @@ -223,3 +229,12 @@ impl<Item: Debug, const INLINE: usize, Heap: Allocator> Debug for IntoIter<Item,
f.debug_tuple("IntoIter").field(&self.as_ref()).finish()
}
}

#[cfg(feature = "defmt")]
impl<Item: DeFormat, const INLINE: usize, Heap: Allocator> DeFormat
for IntoIter<Item, INLINE, Heap>
{
fn format(&self, fmt: DeFormatter) {
dewrite!(fmt, "IntoIter({=[?]})", self.as_ref());
}
}
17 changes: 17 additions & 0 deletions src/iterators/splice.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#[cfg(feature = "defmt")]
use defmt::{
Format as DeFormat,
Formatter as DeFormatter,
write as dewrite
};
use {
super::{
super::{
Expand Down Expand Up @@ -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,
<I as Iterator>::Item: DeFormat
{
fn format(&self, fmt: DeFormatter) {
dewrite!(fmt, "Splice({})", self.drain);
}
}

impl<I: Iterator, const INLINE: usize, Heap: Allocator> Iterator for Splice<'_, I, INLINE, Heap> {
type Item = I::Item;

Expand Down
38 changes: 37 additions & 1 deletion src/locatedlength.rs
Original file line number Diff line number Diff line change
@@ -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*.
Expand All @@ -23,6 +36,29 @@ impl<Item> Clone for LocatedLength<Item> {

impl<Item> Copy for LocatedLength<Item> {}

impl<Item> Debug for LocatedLength<Item> {
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<Item> DeFormat for LocatedLength<Item> {
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<Item> LocatedLength<Item> {
const MAX_LEN: usize = usize::MAX >> Self::SHIFT;
Expand Down
26 changes: 26 additions & 0 deletions src/rawsmallvec.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#[cfg(feature = "defmt")]
use defmt::{
Format as DeFormat,
Formatter as DeFormatter,
write as dewrite
};
use {
super::{
allocator::Allocator,
Expand All @@ -6,6 +12,11 @@ use {
},
core::{
alloc::Layout,
fmt::{
Debug,
Formatter,
Result as Format
},
mem::{
ManuallyDrop,
MaybeUninit
Expand All @@ -23,6 +34,21 @@ pub union RawSmallVec<Item, const INLINE: usize> {
pub heap: (NonNull<Item>, usize)
}

// The active member is tracked by `LocatedLength`, not by the union itself, so
// neither member can be read safely here.
impl<Item, const INLINE: usize> Debug for RawSmallVec<Item, INLINE> {
fn fmt(&self, f: &mut Formatter<'_>) -> Format {
f.debug_struct("RawSmallVec").finish_non_exhaustive()
}
}

#[cfg(feature = "defmt")]
impl<Item, const INLINE: usize> DeFormat for RawSmallVec<Item, INLINE> {
fn format(&self, fmt: DeFormatter) {
dewrite!(fmt, "RawSmallVec {{ .. }}");
}
}

impl<Item, const INLINE: usize> RawSmallVec<Item, INLINE> {
pub const INLINE_CAP: usize = if Self::IS_ZST { usize::MAX } else { INLINE };
const IS_ZST: bool = size_of::<Item>() == 0;
Expand Down
Loading