Skip to main content

non_empty_slice/
ownership.rs

1#[cfg(not(feature = "ownership"))]
2compile_error!("expected `ownership` to be enabled");
3
4#[cfg(any(feature = "std", feature = "alloc"))]
5mod impl_into_owned {
6    use ownership::IntoOwned;
7
8    use crate::{boxed::NonEmptyBoxedSlice, vec::NonEmptyVec};
9
10    impl<T: IntoOwned> IntoOwned for NonEmptyVec<T> {
11        type Owned = NonEmptyVec<T::Owned>;
12
13        fn into_owned(self) -> Self::Owned {
14            // SAFETY: `into_owned` can not make the vector empty
15            unsafe { Self::Owned::new_unchecked(self.into_vec().into_owned()) }
16        }
17    }
18
19    impl<T: IntoOwned> IntoOwned for NonEmptyBoxedSlice<T> {
20        type Owned = NonEmptyBoxedSlice<T::Owned>;
21
22        fn into_owned(self) -> Self::Owned {
23            self.into_non_empty_vec()
24                .into_owned()
25                .into_non_empty_boxed_slice()
26        }
27    }
28}