diff --git a/src/tinyvec.rs b/src/tinyvec.rs index ab4e5e4..c28e3ad 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -665,6 +665,37 @@ impl From> for TinyVec { } } +impl From<&'_ [T]> for TinyVec +where + T: Clone + Default, + A: Array + Default, +{ + #[inline] + #[must_use] + fn from(slice: &[T]) -> Self { + if slice.len() > A::CAPACITY { + TinyVec::Heap(slice.into()) + } else { + let mut arr = ArrayVec::new(); + arr.extend_from_slice(slice); + + TinyVec::Inline(arr) + } + } +} + +impl From<&'_ mut [T]> for TinyVec +where + T: Clone + Default, + A: Array + Default, +{ + #[inline] + #[must_use] + fn from(slice: &mut [T]) -> Self { + Self::from(&*slice) + } +} + impl FromIterator for TinyVec { #[inline] #[must_use]