ownable_core/traits/
iter.rs1use crate::traits::{IntoOwned, ToBorrowed, ToOwned};
2use alloc::collections::{BTreeSet, BinaryHeap, LinkedList, VecDeque};
3use alloc::vec::Vec;
4
5macro_rules! iter_impl {
7 ($ty:ident, $($extra:tt)?) => {
8 impl<'a, T> ToBorrowed<'a> for $ty<T>
9 where
10 T: ToBorrowed<'a> $(+ $extra)?,
11 {
12 #[inline]
13 fn to_borrowed(&'a self) -> Self {
14 self.iter().map(ToBorrowed::to_borrowed).collect()
15 }
16 }
17
18 impl<T> ToOwned for $ty<T>
19 where
20 T: ToOwned,
21 $( <T as ToOwned>::Owned: $extra,)?
22 {
23 type Owned = $ty<T::Owned>;
24
25 #[inline]
26 fn to_owned(&self) -> Self::Owned {
27 self.iter().map(ToOwned::to_owned).collect()
28 }
29 }
30
31 impl<T> IntoOwned for $ty<T>
32 where
33 T: IntoOwned,
34 $( <T as IntoOwned>::Owned: $extra,)?
35 {
36 type Owned = $ty<T::Owned>;
37
38 #[inline]
39 fn into_owned(self) -> Self::Owned {
40 self.into_iter().map(IntoOwned::into_owned).collect()
41 }
42 }
43 };
44}
45
46iter_impl!(Vec,);
47iter_impl!(VecDeque,);
48iter_impl!(LinkedList,);
49iter_impl!(BinaryHeap, Ord);
50iter_impl!(BTreeSet, Ord);