1 | // This file is part of ICU4X. For terms of use, please see the file |
2 | // called LICENSE at the top level of the ICU4X source tree |
3 | // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
4 | |
5 | use crate::map::ZeroMapKV; |
6 | use crate::ule::*; |
7 | use crate::vecs::{FlexZeroSlice, FlexZeroVec}; |
8 | use crate::{VarZeroSlice, VarZeroVec, ZeroMap, ZeroMap2d, ZeroSlice, ZeroVec}; |
9 | use zerofrom::ZeroFrom; |
10 | |
11 | impl<'zf, T> ZeroFrom<'zf, ZeroVec<'_, T>> for ZeroVec<'zf, T> |
12 | where |
13 | T: 'static + AsULE + ?Sized, |
14 | { |
15 | #[inline ] |
16 | fn zero_from(other: &'zf ZeroVec<'_, T>) -> Self { |
17 | ZeroVec::new_borrowed(other.as_ule_slice()) |
18 | } |
19 | } |
20 | |
21 | impl<'zf, T> ZeroFrom<'zf, ZeroSlice<T>> for ZeroVec<'zf, T> |
22 | where |
23 | T: 'static + AsULE + ?Sized, |
24 | { |
25 | #[inline ] |
26 | fn zero_from(other: &'zf ZeroSlice<T>) -> Self { |
27 | ZeroVec::new_borrowed(other.as_ule_slice()) |
28 | } |
29 | } |
30 | |
31 | impl<'zf, T> ZeroFrom<'zf, ZeroSlice<T>> for &'zf ZeroSlice<T> |
32 | where |
33 | T: 'static + AsULE + ?Sized, |
34 | { |
35 | #[inline ] |
36 | fn zero_from(other: &'zf ZeroSlice<T>) -> Self { |
37 | other |
38 | } |
39 | } |
40 | |
41 | impl<'zf> ZeroFrom<'zf, FlexZeroVec<'_>> for FlexZeroVec<'zf> { |
42 | #[inline ] |
43 | fn zero_from(other: &'zf FlexZeroVec<'_>) -> Self { |
44 | FlexZeroVec::Borrowed(other) |
45 | } |
46 | } |
47 | |
48 | impl<'zf> ZeroFrom<'zf, FlexZeroSlice> for FlexZeroVec<'zf> { |
49 | #[inline ] |
50 | fn zero_from(other: &'zf FlexZeroSlice) -> Self { |
51 | FlexZeroVec::Borrowed(other) |
52 | } |
53 | } |
54 | |
55 | impl<'zf> ZeroFrom<'zf, FlexZeroSlice> for &'zf FlexZeroSlice { |
56 | #[inline ] |
57 | fn zero_from(other: &'zf FlexZeroSlice) -> Self { |
58 | other |
59 | } |
60 | } |
61 | |
62 | impl<'zf, T> ZeroFrom<'zf, VarZeroSlice<T>> for VarZeroVec<'zf, T> |
63 | where |
64 | T: 'static + VarULE + ?Sized, |
65 | { |
66 | #[inline ] |
67 | fn zero_from(other: &'zf VarZeroSlice<T>) -> Self { |
68 | other.into() |
69 | } |
70 | } |
71 | |
72 | impl<'zf, T> ZeroFrom<'zf, VarZeroVec<'_, T>> for VarZeroVec<'zf, T> |
73 | where |
74 | T: 'static + VarULE + ?Sized, |
75 | { |
76 | #[inline ] |
77 | fn zero_from(other: &'zf VarZeroVec<'_, T>) -> Self { |
78 | other.as_slice().into() |
79 | } |
80 | } |
81 | |
82 | impl<'zf, T> ZeroFrom<'zf, VarZeroSlice<T>> for &'zf VarZeroSlice<T> |
83 | where |
84 | T: 'static + VarULE + ?Sized, |
85 | { |
86 | #[inline ] |
87 | fn zero_from(other: &'zf VarZeroSlice<T>) -> Self { |
88 | other |
89 | } |
90 | } |
91 | |
92 | impl<'zf, 's, K, V> ZeroFrom<'zf, ZeroMap<'s, K, V>> for ZeroMap<'zf, K, V> |
93 | where |
94 | K: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
95 | V: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
96 | <K as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K as ZeroMapKV<'s>>::Container>, |
97 | <V as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <V as ZeroMapKV<'s>>::Container>, |
98 | { |
99 | fn zero_from(other: &'zf ZeroMap<'s, K, V>) -> Self { |
100 | ZeroMap { |
101 | keys: K::Container::zero_from(&other.keys), |
102 | values: V::Container::zero_from(&other.values), |
103 | } |
104 | } |
105 | } |
106 | |
107 | impl<'zf, 's, K0, K1, V> ZeroFrom<'zf, ZeroMap2d<'s, K0, K1, V>> for ZeroMap2d<'zf, K0, K1, V> |
108 | where |
109 | K0: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
110 | K1: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
111 | V: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
112 | <K0 as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K0 as ZeroMapKV<'s>>::Container>, |
113 | <K1 as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K1 as ZeroMapKV<'s>>::Container>, |
114 | <V as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <V as ZeroMapKV<'s>>::Container>, |
115 | { |
116 | fn zero_from(other: &'zf ZeroMap2d<'s, K0, K1, V>) -> Self { |
117 | ZeroMap2d { |
118 | keys0: K0::Container::zero_from(&other.keys0), |
119 | joiner: ZeroVec::zero_from(&other.joiner), |
120 | keys1: K1::Container::zero_from(&other.keys1), |
121 | values: V::Container::zero_from(&other.values), |
122 | } |
123 | } |
124 | } |
125 | |