Debian Codegraph @

debian/rust-vendor/zerovec/src/zerofrom_impls.rs

raw
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 #[cfg(feature = "alloc")]
6 use crate::map::ZeroMapKV;
7 use crate::ule::*;
8 use crate::vecs::VarZeroVecFormat;
9 use crate::{VarZeroSlice, VarZeroVec, ZeroSlice, ZeroVec};
10 #[cfg(feature = "alloc")]
11 use crate::{ZeroMap, ZeroMap2d};
12 use zerofrom::ZeroFrom;
13
14 impl<'zf, T> ZeroFrom<'zf, ZeroVec<'_, T>> for ZeroVec<'zf, T>
15 where
16 T: 'static + AsULE,
17 {
18 #[inline]
19 fn zero_from(other: &'zf ZeroVec<'_, T>) -> Self {
20 ZeroVec::new_borrowed(other.as_ule_slice())
21 }
22 }
23
24 impl<'zf, T> ZeroFrom<'zf, ZeroSlice<T>> for ZeroVec<'zf, T>
25 where
26 T: 'static + AsULE,
27 {
28 #[inline]
29 fn zero_from(other: &'zf ZeroSlice<T>) -> Self {
30 ZeroVec::new_borrowed(other.as_ule_slice())
31 }
32 }
33
34 impl<'zf, T> ZeroFrom<'zf, ZeroSlice<T>> for &'zf ZeroSlice<T>
35 where
36 T: 'static + AsULE,
37 {
38 #[inline]
39 fn zero_from(other: &'zf ZeroSlice<T>) -> Self {
40 other
41 }
42 }
43
44 impl<'zf, T, F: VarZeroVecFormat> ZeroFrom<'zf, VarZeroSlice<T, F>> for VarZeroVec<'zf, T, F>
45 where
46 T: 'static + VarULE + ?Sized,
47 {
48 #[inline]
49 fn zero_from(other: &'zf VarZeroSlice<T, F>) -> Self {
50 other.into()
51 }
52 }
53
54 impl<'zf, T, F: VarZeroVecFormat> ZeroFrom<'zf, VarZeroVec<'_, T, F>> for VarZeroVec<'zf, T, F>
55 where
56 T: 'static + VarULE + ?Sized,
57 {
58 #[inline]
59 fn zero_from(other: &'zf VarZeroVec<'_, T, F>) -> Self {
60 other.as_slice().into()
61 }
62 }
63
64 impl<'zf, T> ZeroFrom<'zf, VarZeroSlice<T>> for &'zf VarZeroSlice<T>
65 where
66 T: 'static + VarULE + ?Sized,
67 {
68 #[inline]
69 fn zero_from(other: &'zf VarZeroSlice<T>) -> Self {
70 other
71 }
72 }
73
74 #[cfg(feature = "alloc")]
75 impl<'zf, 's, K, V> ZeroFrom<'zf, ZeroMap<'s, K, V>> for ZeroMap<'zf, K, V>
76 where
77 K: 'static + for<'b> ZeroMapKV<'b> + ?Sized,
78 V: 'static + for<'b> ZeroMapKV<'b> + ?Sized,
79 <K as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K as ZeroMapKV<'s>>::Container>,
80 <V as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <V as ZeroMapKV<'s>>::Container>,
81 {
82 fn zero_from(other: &'zf ZeroMap<'s, K, V>) -> Self {
83 ZeroMap {
84 keys: K::Container::zero_from(&other.keys),
85 values: V::Container::zero_from(&other.values),
86 }
87 }
88 }
89
90 #[cfg(feature = "alloc")]
91 impl<'zf, 's, K0, K1, V> ZeroFrom<'zf, ZeroMap2d<'s, K0, K1, V>> for ZeroMap2d<'zf, K0, K1, V>
92 where
93 K0: 'static + for<'b> ZeroMapKV<'b> + ?Sized,
94 K1: 'static + for<'b> ZeroMapKV<'b> + ?Sized,
95 V: 'static + for<'b> ZeroMapKV<'b> + ?Sized,
96 <K0 as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K0 as ZeroMapKV<'s>>::Container>,
97 <K1 as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K1 as ZeroMapKV<'s>>::Container>,
98 <V as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <V as ZeroMapKV<'s>>::Container>,
99 {
100 fn zero_from(other: &'zf ZeroMap2d<'s, K0, K1, V>) -> Self {
101 ZeroMap2d {
102 keys0: K0::Container::zero_from(&other.keys0),
103 joiner: ZeroVec::zero_from(&other.joiner),
104 keys1: K1::Container::zero_from(&other.keys1),
105 values: V::Container::zero_from(&other.values),
106 }
107 }
108 }