diff --git a/src/slice.rs b/src/slice.rs index b0ec4fe..b1236fd 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -1,6 +1,10 @@ use core::ops::{Deref, DerefMut}; use core::fmt; +#[cfg(feature = "use_std")] +use std::boxed::Box; +#[cfg(all(feature = "use_alloc", not(feature = "use_std")))] +use alloc::boxed::Box; #[cfg(feature = "use_std")] use std::vec::Vec; #[cfg(all(feature = "use_collections", not(feature = "use_std")))] @@ -48,6 +52,25 @@ impl<'a, T: 'a> From<&'a mut [T]> for ManagedSlice<'a, T> { } } +macro_rules! from_unboxed_slice { + ($n:expr) => ( + impl<'a, T> From<[T; $n]> for ManagedSlice<'a, T> { + #[inline] + fn from(value: [T; $n]) -> Self { + ManagedSlice::Owned((Box::new(value) as Box<[T]>).into_vec()) + } + } + ); + ($n:expr, $( $r:expr ),*) => ( + from_unboxed_slice!($n); + from_unboxed_slice!($( $r ),*); + ) +} + +#[cfg(any(feature = "use_std", all(feature = "use_alloc", feature = "use_collections")))] +from_unboxed_slice!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32); + #[cfg(any(feature = "use_std", feature = "use_collections"))] impl From> for ManagedSlice<'static, T> { fn from(value: Vec) -> Self {