1cfg_select! {
4 feature = "std" => {
5 use std::borrow::Cow;
6 }
7 feature = "alloc" => {
8 use alloc::borrow::Cow;
9 }
10 _ => {
11 compile_error!("expected either `std` or `alloc` to be enabled");
12 }
13}
14
15use crate::{boxed::NonEmptyBoxedSlice, slice::NonEmptySlice, vec::NonEmptyVec};
16
17pub type CowSlice<'a, T> = Cow<'a, [T]>;
19
20pub type NonEmptyCowSlice<'a, T> = Cow<'a, NonEmptySlice<T>>;
22
23impl<T: Clone> From<NonEmptyCowSlice<'_, T>> for NonEmptyVec<T> {
24 fn from(non_empty: NonEmptyCowSlice<'_, T>) -> Self {
25 non_empty.into_owned()
26 }
27}
28
29impl<T: Clone> From<NonEmptyCowSlice<'_, T>> for NonEmptyBoxedSlice<T> {
30 fn from(non_empty: NonEmptyCowSlice<'_, T>) -> Self {
31 non_empty.into_owned().into_non_empty_boxed_slice()
32 }
33}
34
35impl<'a, T: Clone> From<&'a NonEmptySlice<T>> for NonEmptyCowSlice<'a, T> {
36 fn from(non_empty: &'a NonEmptySlice<T>) -> Self {
37 Self::Borrowed(non_empty)
38 }
39}
40
41impl<T: Clone> From<NonEmptyVec<T>> for NonEmptyCowSlice<'_, T> {
42 fn from(non_empty: NonEmptyVec<T>) -> Self {
43 Self::Owned(non_empty)
44 }
45}
46
47impl<'a, T: Clone> From<&'a NonEmptyVec<T>> for NonEmptyCowSlice<'a, T> {
48 fn from(non_empty: &'a NonEmptyVec<T>) -> Self {
49 Self::Borrowed(non_empty.as_non_empty_slice())
50 }
51}