zerovec/
zerofrom_impls.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use crate::map::ZeroMapKV;
use crate::ule::*;
use crate::vecs::{FlexZeroSlice, FlexZeroVec};
use crate::{VarZeroSlice, VarZeroVec, ZeroMap, ZeroMap2d, ZeroSlice, ZeroVec};
use zerofrom::ZeroFrom;

impl<'zf, T> ZeroFrom<'zf, ZeroVec<'_, T>> for ZeroVec<'zf, T>
where
    T: 'static + AsULE + ?Sized,
{
    #[inline]
    fn zero_from(other: &'zf ZeroVec<'_, T>) -> Self {
        ZeroVec::new_borrowed(other.as_ule_slice())
    }
}

impl<'zf, T> ZeroFrom<'zf, ZeroSlice<T>> for ZeroVec<'zf, T>
where
    T: 'static + AsULE + ?Sized,
{
    #[inline]
    fn zero_from(other: &'zf ZeroSlice<T>) -> Self {
        ZeroVec::new_borrowed(other.as_ule_slice())
    }
}

impl<'zf, T> ZeroFrom<'zf, ZeroSlice<T>> for &'zf ZeroSlice<T>
where
    T: 'static + AsULE + ?Sized,
{
    #[inline]
    fn zero_from(other: &'zf ZeroSlice<T>) -> Self {
        other
    }
}

impl<'zf> ZeroFrom<'zf, FlexZeroVec<'_>> for FlexZeroVec<'zf> {
    #[inline]
    fn zero_from(other: &'zf FlexZeroVec<'_>) -> Self {
        FlexZeroVec::Borrowed(other)
    }
}

impl<'zf> ZeroFrom<'zf, FlexZeroSlice> for FlexZeroVec<'zf> {
    #[inline]
    fn zero_from(other: &'zf FlexZeroSlice) -> Self {
        FlexZeroVec::Borrowed(other)
    }
}

impl<'zf> ZeroFrom<'zf, FlexZeroSlice> for &'zf FlexZeroSlice {
    #[inline]
    fn zero_from(other: &'zf FlexZeroSlice) -> Self {
        other
    }
}

impl<'zf, T> ZeroFrom<'zf, VarZeroSlice<T>> for VarZeroVec<'zf, T>
where
    T: 'static + VarULE + ?Sized,
{
    #[inline]
    fn zero_from(other: &'zf VarZeroSlice<T>) -> Self {
        other.into()
    }
}

impl<'zf, T> ZeroFrom<'zf, VarZeroVec<'_, T>> for VarZeroVec<'zf, T>
where
    T: 'static + VarULE + ?Sized,
{
    #[inline]
    fn zero_from(other: &'zf VarZeroVec<'_, T>) -> Self {
        other.as_slice().into()
    }
}

impl<'zf, T> ZeroFrom<'zf, VarZeroSlice<T>> for &'zf VarZeroSlice<T>
where
    T: 'static + VarULE + ?Sized,
{
    #[inline]
    fn zero_from(other: &'zf VarZeroSlice<T>) -> Self {
        other
    }
}

impl<'zf, 's, K, V> ZeroFrom<'zf, ZeroMap<'s, K, V>> for ZeroMap<'zf, K, V>
where
    K: 'static + for<'b> ZeroMapKV<'b> + ?Sized,
    V: 'static + for<'b> ZeroMapKV<'b> + ?Sized,
    <K as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K as ZeroMapKV<'s>>::Container>,
    <V as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <V as ZeroMapKV<'s>>::Container>,
{
    fn zero_from(other: &'zf ZeroMap<'s, K, V>) -> Self {
        ZeroMap {
            keys: K::Container::zero_from(&other.keys),
            values: V::Container::zero_from(&other.values),
        }
    }
}

impl<'zf, 's, K0, K1, V> ZeroFrom<'zf, ZeroMap2d<'s, K0, K1, V>> for ZeroMap2d<'zf, K0, K1, V>
where
    K0: 'static + for<'b> ZeroMapKV<'b> + ?Sized,
    K1: 'static + for<'b> ZeroMapKV<'b> + ?Sized,
    V: 'static + for<'b> ZeroMapKV<'b> + ?Sized,
    <K0 as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K0 as ZeroMapKV<'s>>::Container>,
    <K1 as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <K1 as ZeroMapKV<'s>>::Container>,
    <V as ZeroMapKV<'zf>>::Container: ZeroFrom<'zf, <V as ZeroMapKV<'s>>::Container>,
{
    fn zero_from(other: &'zf ZeroMap2d<'s, K0, K1, V>) -> Self {
        ZeroMap2d {
            keys0: K0::Container::zero_from(&other.keys0),
            joiner: ZeroVec::zero_from(&other.joiner),
            keys1: K1::Container::zero_from(&other.keys1),
            values: V::Container::zero_from(&other.values),
        }
    }
}