/rust/registry/src/index.crates.io-1949cf8c6b5b557f/ahash-0.8.11/src/convert.rs
Line | Count | Source |
1 | | pub(crate) trait Convert<To> { |
2 | | fn convert(self) -> To; |
3 | | } |
4 | | |
5 | | macro_rules! convert { |
6 | | ($a:ty, $b:ty) => { |
7 | | impl Convert<$b> for $a { |
8 | | #[inline(always)] |
9 | 0 | fn convert(self) -> $b { |
10 | 0 | zerocopy::transmute!(self) |
11 | 0 | } Unexecuted instantiation: <u128 as ahash::convert::Convert<[u64; 2]>>::convert Unexecuted instantiation: <u16 as ahash::convert::Convert<[u8; 2]>>::convert Unexecuted instantiation: <[[u64; 4]; 2] as ahash::convert::Convert<[u8; 64]>>::convert Unexecuted instantiation: <[f64; 2] as ahash::convert::Convert<[u8; 16]>>::convert Unexecuted instantiation: <[f32; 4] as ahash::convert::Convert<[u8; 16]>>::convert Unexecuted instantiation: <f64 as ahash::convert::Convert<[u8; 8]>>::convert Unexecuted instantiation: <[u128; 4] as ahash::convert::Convert<[u32; 16]>>::convert Unexecuted instantiation: <[f32; 2] as ahash::convert::Convert<[u8; 8]>>::convert Unexecuted instantiation: <f32 as ahash::convert::Convert<[u8; 4]>>::convert Unexecuted instantiation: <[u128; 4] as ahash::convert::Convert<[u16; 32]>>::convert Unexecuted instantiation: <[u128; 4] as ahash::convert::Convert<[u8; 64]>>::convert Unexecuted instantiation: <[u128; 2] as ahash::convert::Convert<[u64; 4]>>::convert Unexecuted instantiation: <[u128; 2] as ahash::convert::Convert<[u32; 8]>>::convert Unexecuted instantiation: <[u64; 2] as ahash::convert::Convert<[u16; 8]>>::convert Unexecuted instantiation: <[u64; 2] as ahash::convert::Convert<[u8; 16]>>::convert Unexecuted instantiation: <[u32; 4] as ahash::convert::Convert<[u16; 8]>>::convert Unexecuted instantiation: <[u32; 4] as ahash::convert::Convert<[u8; 16]>>::convert Unexecuted instantiation: <[u16; 8] as ahash::convert::Convert<[u8; 16]>>::convert Unexecuted instantiation: <u64 as ahash::convert::Convert<[u32; 2]>>::convert Unexecuted instantiation: <u64 as ahash::convert::Convert<[u16; 4]>>::convert Unexecuted instantiation: <u64 as ahash::convert::Convert<[u8; 8]>>::convert Unexecuted instantiation: <[u32; 2] as ahash::convert::Convert<[u16; 4]>>::convert Unexecuted instantiation: <[u32; 2] as ahash::convert::Convert<[u8; 8]>>::convert Unexecuted instantiation: <u32 as ahash::convert::Convert<[u16; 2]>>::convert Unexecuted instantiation: <u32 as ahash::convert::Convert<[u8; 4]>>::convert Unexecuted instantiation: <[u16; 2] as ahash::convert::Convert<[u8; 4]>>::convert Unexecuted instantiation: <[u128; 4] as ahash::convert::Convert<[u64; 8]>>::convert Unexecuted instantiation: <[u128; 2] as ahash::convert::Convert<[u16; 16]>>::convert Unexecuted instantiation: <[u128; 2] as ahash::convert::Convert<[u8; 32]>>::convert Unexecuted instantiation: <u128 as ahash::convert::Convert<[u32; 4]>>::convert Unexecuted instantiation: <u128 as ahash::convert::Convert<[u16; 8]>>::convert Unexecuted instantiation: <u128 as ahash::convert::Convert<[u8; 16]>>::convert Unexecuted instantiation: <[u64; 8] as ahash::convert::Convert<[u32; 16]>>::convert Unexecuted instantiation: <[u64; 8] as ahash::convert::Convert<[u16; 32]>>::convert Unexecuted instantiation: <[u64; 8] as ahash::convert::Convert<[u8; 64]>>::convert Unexecuted instantiation: <[u64; 4] as ahash::convert::Convert<[u32; 8]>>::convert Unexecuted instantiation: <[u64; 4] as ahash::convert::Convert<[u16; 16]>>::convert Unexecuted instantiation: <[u64; 4] as ahash::convert::Convert<[u8; 32]>>::convert Unexecuted instantiation: <[u64; 2] as ahash::convert::Convert<[u32; 4]>>::convert |
12 | | } |
13 | | impl Convert<$a> for $b { |
14 | | #[inline(always)] |
15 | 0 | fn convert(self) -> $a { |
16 | 0 | zerocopy::transmute!(self) |
17 | 0 | } Unexecuted instantiation: <[u8; 2] as ahash::convert::Convert<u16>>::convert Unexecuted instantiation: <[u8; 8] as ahash::convert::Convert<u64>>::convert Unexecuted instantiation: <[u8; 4] as ahash::convert::Convert<u32>>::convert Unexecuted instantiation: <[u64; 2] as ahash::convert::Convert<u128>>::convert Unexecuted instantiation: <[u8; 16] as ahash::convert::Convert<u128>>::convert Unexecuted instantiation: <[u64; 8] as ahash::convert::Convert<[u128; 4]>>::convert Unexecuted instantiation: <[u8; 4] as ahash::convert::Convert<[u16; 2]>>::convert Unexecuted instantiation: <[u8; 64] as ahash::convert::Convert<[[u64; 4]; 2]>>::convert Unexecuted instantiation: <[u8; 16] as ahash::convert::Convert<[f64; 2]>>::convert Unexecuted instantiation: <[u8; 16] as ahash::convert::Convert<[f32; 4]>>::convert Unexecuted instantiation: <[u8; 8] as ahash::convert::Convert<f64>>::convert Unexecuted instantiation: <[u8; 8] as ahash::convert::Convert<[f32; 2]>>::convert Unexecuted instantiation: <[u8; 4] as ahash::convert::Convert<f32>>::convert Unexecuted instantiation: <[u32; 16] as ahash::convert::Convert<[u128; 4]>>::convert Unexecuted instantiation: <[u16; 32] as ahash::convert::Convert<[u128; 4]>>::convert Unexecuted instantiation: <[u8; 64] as ahash::convert::Convert<[u128; 4]>>::convert Unexecuted instantiation: <[u64; 4] as ahash::convert::Convert<[u128; 2]>>::convert Unexecuted instantiation: <[u32; 4] as ahash::convert::Convert<[u64; 2]>>::convert Unexecuted instantiation: <[u16; 8] as ahash::convert::Convert<[u64; 2]>>::convert Unexecuted instantiation: <[u8; 16] as ahash::convert::Convert<[u64; 2]>>::convert Unexecuted instantiation: <[u16; 8] as ahash::convert::Convert<[u32; 4]>>::convert Unexecuted instantiation: <[u8; 16] as ahash::convert::Convert<[u32; 4]>>::convert Unexecuted instantiation: <[u8; 16] as ahash::convert::Convert<[u16; 8]>>::convert Unexecuted instantiation: <[u32; 2] as ahash::convert::Convert<u64>>::convert Unexecuted instantiation: <[u16; 4] as ahash::convert::Convert<u64>>::convert Unexecuted instantiation: <[u16; 4] as ahash::convert::Convert<[u32; 2]>>::convert Unexecuted instantiation: <[u8; 8] as ahash::convert::Convert<[u32; 2]>>::convert Unexecuted instantiation: <[u16; 2] as ahash::convert::Convert<u32>>::convert Unexecuted instantiation: <[u32; 8] as ahash::convert::Convert<[u128; 2]>>::convert Unexecuted instantiation: <[u16; 16] as ahash::convert::Convert<[u128; 2]>>::convert Unexecuted instantiation: <[u8; 32] as ahash::convert::Convert<[u128; 2]>>::convert Unexecuted instantiation: <[u32; 4] as ahash::convert::Convert<u128>>::convert Unexecuted instantiation: <[u16; 8] as ahash::convert::Convert<u128>>::convert Unexecuted instantiation: <[u32; 16] as ahash::convert::Convert<[u64; 8]>>::convert Unexecuted instantiation: <[u16; 32] as ahash::convert::Convert<[u64; 8]>>::convert Unexecuted instantiation: <[u8; 64] as ahash::convert::Convert<[u64; 8]>>::convert Unexecuted instantiation: <[u32; 8] as ahash::convert::Convert<[u64; 4]>>::convert Unexecuted instantiation: <[u16; 16] as ahash::convert::Convert<[u64; 4]>>::convert Unexecuted instantiation: <[u8; 32] as ahash::convert::Convert<[u64; 4]>>::convert |
18 | | } |
19 | | }; |
20 | | } |
21 | | |
22 | | convert!([u128; 4], [u64; 8]); |
23 | | convert!([u128; 4], [u32; 16]); |
24 | | convert!([u128; 4], [u16; 32]); |
25 | | convert!([u128; 4], [u8; 64]); |
26 | | convert!([u128; 2], [u64; 4]); |
27 | | convert!([u128; 2], [u32; 8]); |
28 | | convert!([u128; 2], [u16; 16]); |
29 | | convert!([u128; 2], [u8; 32]); |
30 | | convert!(u128, [u64; 2]); |
31 | | convert!(u128, [u32; 4]); |
32 | | convert!(u128, [u16; 8]); |
33 | | convert!(u128, [u8; 16]); |
34 | | convert!([u64; 8], [u32; 16]); |
35 | | convert!([u64; 8], [u16; 32]); |
36 | | convert!([u64; 8], [u8; 64]); |
37 | | convert!([u64; 4], [u32; 8]); |
38 | | convert!([u64; 4], [u16; 16]); |
39 | | convert!([u64; 4], [u8; 32]); |
40 | | convert!([u64; 2], [u32; 4]); |
41 | | convert!([u64; 2], [u16; 8]); |
42 | | convert!([u64; 2], [u8; 16]); |
43 | | convert!([u32; 4], [u16; 8]); |
44 | | convert!([u32; 4], [u8; 16]); |
45 | | convert!([u16; 8], [u8; 16]); |
46 | | convert!(u64, [u32; 2]); |
47 | | convert!(u64, [u16; 4]); |
48 | | convert!(u64, [u8; 8]); |
49 | | convert!([u32; 2], [u16; 4]); |
50 | | convert!([u32; 2], [u8; 8]); |
51 | | convert!(u32, [u16; 2]); |
52 | | convert!(u32, [u8; 4]); |
53 | | convert!([u16; 2], [u8; 4]); |
54 | | convert!(u16, [u8; 2]); |
55 | | convert!([[u64; 4]; 2], [u8; 64]); |
56 | | |
57 | | convert!([f64; 2], [u8; 16]); |
58 | | convert!([f32; 4], [u8; 16]); |
59 | | convert!(f64, [u8; 8]); |
60 | | convert!([f32; 2], [u8; 8]); |
61 | | convert!(f32, [u8; 4]); |
62 | | |
63 | | macro_rules! as_array { |
64 | | ($input:expr, $len:expr) => {{ |
65 | | { |
66 | | #[inline(always)] |
67 | 0 | fn as_array<T>(slice: &[T]) -> &[T; $len] { |
68 | 0 | core::convert::TryFrom::try_from(slice).unwrap() |
69 | 0 | } Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_last_u32::as_array::<u8> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_last_u64::as_array::<u8> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_last_u128::as_array::<u8> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_u16::as_array::<u8> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_u32::as_array::<u8> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_u64::as_array::<u8> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_u128::as_array::<u8> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_u128x2::as_array::<_> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_u128x4::as_array::<_> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_last_u16::as_array::<_> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_last_u32::as_array::<_> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_last_u64::as_array::<_> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_last_u128::as_array::<_> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_last_u128x2::as_array::<_> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_last_u128x4::as_array::<_> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_u16::as_array::<_> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_u32::as_array::<_> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_u64::as_array::<_> Unexecuted instantiation: <[u8] as ahash::convert::ReadFromSlice>::read_u128::as_array::<_> |
70 | | as_array($input) |
71 | | } |
72 | | }}; |
73 | | } |
74 | | |
75 | | pub(crate) trait ReadFromSlice { |
76 | | fn read_u16(&self) -> (u16, &[u8]); |
77 | | fn read_u32(&self) -> (u32, &[u8]); |
78 | | fn read_u64(&self) -> (u64, &[u8]); |
79 | | fn read_u128(&self) -> (u128, &[u8]); |
80 | | fn read_u128x2(&self) -> ([u128; 2], &[u8]); |
81 | | fn read_u128x4(&self) -> ([u128; 4], &[u8]); |
82 | | fn read_last_u16(&self) -> u16; |
83 | | fn read_last_u32(&self) -> u32; |
84 | | fn read_last_u64(&self) -> u64; |
85 | | fn read_last_u128(&self) -> u128; |
86 | | fn read_last_u128x2(&self) -> [u128; 2]; |
87 | | fn read_last_u128x4(&self) -> [u128; 4]; |
88 | | } |
89 | | |
90 | | impl ReadFromSlice for [u8] { |
91 | | #[inline(always)] |
92 | 0 | fn read_u16(&self) -> (u16, &[u8]) { |
93 | 0 | let (value, rest) = self.split_at(2); |
94 | 0 | (as_array!(value, 2).convert(), rest) |
95 | 0 | } |
96 | | |
97 | | #[inline(always)] |
98 | 0 | fn read_u32(&self) -> (u32, &[u8]) { |
99 | 0 | let (value, rest) = self.split_at(4); |
100 | 0 | (as_array!(value, 4).convert(), rest) |
101 | 0 | } |
102 | | |
103 | | #[inline(always)] |
104 | 0 | fn read_u64(&self) -> (u64, &[u8]) { |
105 | 0 | let (value, rest) = self.split_at(8); |
106 | 0 | (as_array!(value, 8).convert(), rest) |
107 | 0 | } |
108 | | |
109 | | #[inline(always)] |
110 | 0 | fn read_u128(&self) -> (u128, &[u8]) { |
111 | 0 | let (value, rest) = self.split_at(16); |
112 | 0 | (as_array!(value, 16).convert(), rest) |
113 | 0 | } |
114 | | |
115 | | #[inline(always)] |
116 | 0 | fn read_u128x2(&self) -> ([u128; 2], &[u8]) { |
117 | 0 | let (value, rest) = self.split_at(32); |
118 | 0 | (as_array!(value, 32).convert(), rest) |
119 | 0 | } |
120 | | |
121 | | #[inline(always)] |
122 | 0 | fn read_u128x4(&self) -> ([u128; 4], &[u8]) { |
123 | 0 | let (value, rest) = self.split_at(64); |
124 | 0 | (as_array!(value, 64).convert(), rest) |
125 | 0 | } |
126 | | |
127 | | #[inline(always)] |
128 | 0 | fn read_last_u16(&self) -> u16 { |
129 | 0 | let (_, value) = self.split_at(self.len() - 2); |
130 | 0 | as_array!(value, 2).convert() |
131 | 0 | } |
132 | | |
133 | | #[inline(always)] |
134 | 0 | fn read_last_u32(&self) -> u32 { |
135 | 0 | let (_, value) = self.split_at(self.len() - 4); |
136 | 0 | as_array!(value, 4).convert() |
137 | 0 | } |
138 | | |
139 | | #[inline(always)] |
140 | 0 | fn read_last_u64(&self) -> u64 { |
141 | 0 | let (_, value) = self.split_at(self.len() - 8); |
142 | 0 | as_array!(value, 8).convert() |
143 | 0 | } |
144 | | |
145 | | #[inline(always)] |
146 | 0 | fn read_last_u128(&self) -> u128 { |
147 | 0 | let (_, value) = self.split_at(self.len() - 16); |
148 | 0 | as_array!(value, 16).convert() |
149 | 0 | } |
150 | | |
151 | | #[inline(always)] |
152 | 0 | fn read_last_u128x2(&self) -> [u128; 2] { |
153 | 0 | let (_, value) = self.split_at(self.len() - 32); |
154 | 0 | as_array!(value, 32).convert() |
155 | 0 | } |
156 | | |
157 | | #[inline(always)] |
158 | 0 | fn read_last_u128x4(&self) -> [u128; 4] { |
159 | 0 | let (_, value) = self.split_at(self.len() - 64); |
160 | 0 | as_array!(value, 64).convert() |
161 | 0 | } |
162 | | } |