Skip to content
Open
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extract_if = []
bytes = { version = "1", optional = true, default-features = false }
serde = { version = "1", optional = true, default-features = false }
malloc_size_of = { version = "0.1.1", optional = true, default-features = false }
defmt = { version = "1", optional = true }

[dev-dependencies]
bincode = "1.0.1"
Expand Down
51 changes: 51 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ use serde::{
use std::io;

/// Error type for APIs with fallible heap allocation
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug)]
pub enum CollectionAllocErr {
/// Overflow `usize::MAX` or other error during size computation
Expand Down Expand Up @@ -562,6 +563,18 @@ where
}
}

#[cfg(all(feature = "extract_if", feature = "defmt"))]
#[cfg_attr(docsrs, doc(cfg(feature = "defmt")))]
impl<T, const N: usize, F> defmt::Format for ExtractIf<'_, T, N, F>
where
F: FnMut(&mut T) -> bool,
T: defmt::Format,
{
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(fmt, "ExtractIf({:?})", self.vec.as_slice());
}
}

Comment on lines +566 to +577

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

separate this into its own file defmt.rs and conditionally link it

#[cfg(feature = "extract_if")]
impl<T, F, const N: usize> Iterator for ExtractIf<'_, T, N, F>
where
Expand Down Expand Up @@ -638,6 +651,17 @@ where
}
}

#[cfg(feature = "defmt")]
impl<'a, I, const N: usize> defmt::Format for Splice<'a, I, N>
where
I: Iterator + 'a,
<I as Iterator>::Item: defmt::Format,
{
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(fmt, "Splice({:?})", self.drain);
}
}

Comment on lines +654 to +664

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

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

Expand Down Expand Up @@ -2851,6 +2875,33 @@ impl<T: Debug, const N: usize> Debug for Drain<'_, T, N> {
}
}

#[cfg(feature = "defmt")]
#[cfg_attr(docsrs, doc(cfg(feature = "defmt")))]
impl<T: defmt::Format, const N: usize> defmt::Format for SmallVec<T, N> {
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(fmt, "{=[?]}", self.as_slice());
}
}

#[cfg(feature = "defmt")]
#[cfg_attr(docsrs, doc(cfg(feature = "defmt")))]
impl<T: defmt::Format, const N: usize> defmt::Format for IntoIter<T, N> {
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(fmt, "IntoIter({=[?]})", self.as_slice());
}
}

#[cfg(feature = "defmt")]
#[cfg_attr(docsrs, doc(cfg(feature = "defmt")))]
impl<T: defmt::Format, const N: usize> defmt::Format for Drain<'_, T, N>
where
T: defmt::Format,
{
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(fmt, "Drain({=[?]})", self.iter.as_slice());
}
}

Comment on lines +2878 to +2904

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<T, const N: usize> Serialize for SmallVec<T, N>
Expand Down