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 @@ -32,6 +32,7 @@ malloc_size_of = { version = "0.1", optional = true, default-features = false }
arbitrary = { version = "1", optional = true }
bincode = { version = "2", optional = true, default-features = false }
unty = { version = "0.0.4", optional = true, default-features = false }
defmt = { version = "1", optional = true }

[dev-dependencies]
bincode1 = { package = "bincode", version = "1.0.1" }
Expand Down
35 changes: 35 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
//! For details, see the
//! [Rust Reference](https://doc.rust-lang.org/reference/const_eval.html#const-functions).
//!
//! ### `defmt`
//!
//! When this feature is enabled, `SmallVec` implements the `defmt::Format` trait.
//!
//! ### `drain_filter`
//!
//! **This feature is unstable.** It may change to match the unstable `drain_filter` method in libstd.
Expand Down Expand Up @@ -295,6 +299,7 @@ impl<T: Clone> ExtendFromSlice<T> for Vec<T> {
}

/// 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 @@ -364,6 +369,16 @@ where
}
}

#[cfg(feature = "defmt")]
impl<'a, T: 'a + Array> defmt::Format for Drain<'a, T>
where
T::Item: defmt::Format,
{
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(fmt, "Drain({=[?]})", self.iter.as_slice());
}
}

unsafe impl<'a, T: Sync + Array> Sync for Drain<'a, T> {}
unsafe impl<'a, T: Send + Array> Send for Drain<'a, T> {}

Expand Down Expand Up @@ -2122,6 +2137,16 @@ where
}
}

#[cfg(feature = "defmt")]
impl<A: Array> defmt::Format for SmallVec<A>
where
A::Item: defmt::Format,
{
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(fmt, "{=[?]}", self.as_slice());
}
}

impl<A: Array> Default for SmallVec<A> {
#[inline]
fn default() -> SmallVec<A> {
Expand Down Expand Up @@ -2245,6 +2270,16 @@ where
}
}

#[cfg(feature = "defmt")]
impl<A: Array> defmt::Format for IntoIter<A>
where
A::Item: defmt::Format,
{
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(fmt, "IntoIter({=[?]})", self.as_slice());
}
}

impl<A: Array + Clone> Clone for IntoIter<A>
where
A::Item: Clone,
Expand Down
Loading