Add conversions from unboxed slices.
This commit is contained in:
parent
7a46d7150d
commit
e62a985deb
23
src/slice.rs
23
src/slice.rs
|
@ -1,6 +1,10 @@
|
||||||
use core::ops::{Deref, DerefMut};
|
use core::ops::{Deref, DerefMut};
|
||||||
use core::fmt;
|
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")]
|
#[cfg(feature = "use_std")]
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
#[cfg(all(feature = "use_collections", not(feature = "use_std")))]
|
#[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"))]
|
#[cfg(any(feature = "use_std", feature = "use_collections"))]
|
||||||
impl<T: 'static> From<Vec<T>> for ManagedSlice<'static, T> {
|
impl<T: 'static> From<Vec<T>> for ManagedSlice<'static, T> {
|
||||||
fn from(value: Vec<T>) -> Self {
|
fn from(value: Vec<T>) -> Self {
|
||||||
|
|
Loading…
Reference in New Issue