/rust/registry/src/index.crates.io-6f17d22bba15001f/zerovec-0.10.4/src/yoke_impls.rs
Line | Count | Source (jump to first uncovered line) |
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 | | // This way we can copy-paste Yokeable impls |
6 | | #![allow(unknown_lints)] // forgetting_copy_types |
7 | | #![allow(renamed_and_removed_lints)] // forgetting_copy_types |
8 | | #![allow(forgetting_copy_types)] |
9 | | #![allow(clippy::forget_copy)] |
10 | | #![allow(clippy::forget_non_drop)] |
11 | | |
12 | | use crate::flexzerovec::FlexZeroVec; |
13 | | use crate::map::ZeroMapBorrowed; |
14 | | use crate::map::ZeroMapKV; |
15 | | use crate::map2d::ZeroMap2dBorrowed; |
16 | | use crate::ule::*; |
17 | | use crate::{VarZeroVec, ZeroMap, ZeroMap2d, ZeroVec}; |
18 | | use core::{mem, ptr}; |
19 | | use yoke::*; |
20 | | |
21 | | // This impl is similar to the impl on Cow and is safe for the same reasons |
22 | | /// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate |
23 | | unsafe impl<'a, T: 'static + AsULE + ?Sized> Yokeable<'a> for ZeroVec<'static, T> { |
24 | | type Output = ZeroVec<'a, T>; |
25 | | #[inline] |
26 | 0 | fn transform(&'a self) -> &'a Self::Output { |
27 | 0 | self |
28 | 0 | } |
29 | | #[inline] |
30 | 0 | fn transform_owned(self) -> Self::Output { |
31 | 0 | self |
32 | 0 | } |
33 | | #[inline] |
34 | 0 | unsafe fn make(from: Self::Output) -> Self { |
35 | 0 | debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
36 | 0 | let from = mem::ManuallyDrop::new(from); |
37 | 0 | let ptr: *const Self = (&*from as *const Self::Output).cast(); |
38 | 0 | ptr::read(ptr) |
39 | 0 | } |
40 | | #[inline] |
41 | 0 | fn transform_mut<F>(&'a mut self, f: F) |
42 | 0 | where |
43 | 0 | F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
44 | 0 | { |
45 | 0 | unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
46 | 0 | } |
47 | | } |
48 | | |
49 | | // This impl is similar to the impl on Cow and is safe for the same reasons |
50 | | /// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate |
51 | | unsafe impl<'a, T: 'static + VarULE + ?Sized> Yokeable<'a> for VarZeroVec<'static, T> { |
52 | | type Output = VarZeroVec<'a, T>; |
53 | | #[inline] |
54 | 0 | fn transform(&'a self) -> &'a Self::Output { |
55 | 0 | self |
56 | 0 | } |
57 | | #[inline] |
58 | 0 | fn transform_owned(self) -> Self::Output { |
59 | 0 | self |
60 | 0 | } |
61 | | #[inline] |
62 | 0 | unsafe fn make(from: Self::Output) -> Self { |
63 | 0 | debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
64 | 0 | let from = mem::ManuallyDrop::new(from); |
65 | 0 | let ptr: *const Self = (&*from as *const Self::Output).cast(); |
66 | 0 | ptr::read(ptr) |
67 | 0 | } |
68 | | #[inline] |
69 | 0 | fn transform_mut<F>(&'a mut self, f: F) |
70 | 0 | where |
71 | 0 | F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
72 | 0 | { |
73 | 0 | unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
74 | 0 | } |
75 | | } |
76 | | |
77 | | // This impl is similar to the impl on Cow and is safe for the same reasons |
78 | | /// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate |
79 | | unsafe impl<'a> Yokeable<'a> for FlexZeroVec<'static> { |
80 | | type Output = FlexZeroVec<'a>; |
81 | | #[inline] |
82 | 0 | fn transform(&'a self) -> &'a Self::Output { |
83 | 0 | self |
84 | 0 | } |
85 | | #[inline] |
86 | 0 | fn transform_owned(self) -> Self::Output { |
87 | 0 | self |
88 | 0 | } |
89 | | #[inline] |
90 | 0 | unsafe fn make(from: Self::Output) -> Self { |
91 | 0 | debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
92 | 0 | let from = mem::ManuallyDrop::new(from); |
93 | 0 | let ptr: *const Self = (&*from as *const Self::Output).cast(); |
94 | 0 | ptr::read(ptr) |
95 | 0 | } |
96 | | #[inline] |
97 | 0 | fn transform_mut<F>(&'a mut self, f: F) |
98 | 0 | where |
99 | 0 | F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
100 | 0 | { |
101 | 0 | unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
102 | 0 | } |
103 | | } |
104 | | |
105 | | /// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate |
106 | | #[allow(clippy::transmute_ptr_to_ptr)] |
107 | | unsafe impl<'a, K, V> Yokeable<'a> for ZeroMap<'static, K, V> |
108 | | where |
109 | | K: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
110 | | V: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
111 | | <K as ZeroMapKV<'static>>::Container: for<'b> Yokeable<'b>, |
112 | | <V as ZeroMapKV<'static>>::Container: for<'b> Yokeable<'b>, |
113 | | { |
114 | | type Output = ZeroMap<'a, K, V>; |
115 | | #[inline] |
116 | 0 | fn transform(&'a self) -> &'a Self::Output { |
117 | 0 | unsafe { |
118 | 0 | // Unfortunately, because K and V are generic, rustc is |
119 | 0 | // unaware that these are covariant types, and cannot perform this cast automatically. |
120 | 0 | // We transmute it instead, and enforce the lack of a lifetime with the `K, V: 'static` bound |
121 | 0 | mem::transmute::<&Self, &Self::Output>(self) |
122 | 0 | } |
123 | 0 | } |
124 | | #[inline] |
125 | 0 | fn transform_owned(self) -> Self::Output { |
126 | 0 | debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
127 | | unsafe { |
128 | | // Similar problem as transform(), but we need to use ptr::read since |
129 | | // the compiler isn't sure of the sizes |
130 | 0 | let this = mem::ManuallyDrop::new(self); |
131 | 0 | let ptr: *const Self::Output = (&*this as *const Self).cast(); |
132 | 0 | ptr::read(ptr) |
133 | 0 | } |
134 | 0 | } |
135 | | #[inline] |
136 | 0 | unsafe fn make(from: Self::Output) -> Self { |
137 | 0 | debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
138 | 0 | let from = mem::ManuallyDrop::new(from); |
139 | 0 | let ptr: *const Self = (&*from as *const Self::Output).cast(); |
140 | 0 | ptr::read(ptr) |
141 | 0 | } |
142 | | #[inline] |
143 | 0 | fn transform_mut<F>(&'a mut self, f: F) |
144 | 0 | where |
145 | 0 | F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
146 | 0 | { |
147 | 0 | unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
148 | 0 | } |
149 | | } |
150 | | |
151 | | /// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate |
152 | | #[allow(clippy::transmute_ptr_to_ptr)] |
153 | | unsafe impl<'a, K, V> Yokeable<'a> for ZeroMapBorrowed<'static, K, V> |
154 | | where |
155 | | K: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
156 | | V: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
157 | | &'static <K as ZeroMapKV<'static>>::Slice: for<'b> Yokeable<'b>, |
158 | | &'static <V as ZeroMapKV<'static>>::Slice: for<'b> Yokeable<'b>, |
159 | | { |
160 | | type Output = ZeroMapBorrowed<'a, K, V>; |
161 | | #[inline] |
162 | 0 | fn transform(&'a self) -> &'a Self::Output { |
163 | 0 | unsafe { |
164 | 0 | // Unfortunately, because K and V are generic, rustc is |
165 | 0 | // unaware that these are covariant types, and cannot perform this cast automatically. |
166 | 0 | // We transmute it instead, and enforce the lack of a lifetime with the `K, V: 'static` bound |
167 | 0 | mem::transmute::<&Self, &Self::Output>(self) |
168 | 0 | } |
169 | 0 | } |
170 | | #[inline] |
171 | 0 | fn transform_owned(self) -> Self::Output { |
172 | 0 | debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
173 | | unsafe { |
174 | | // Similar problem as transform(), but we need to use ptr::read since |
175 | | // the compiler isn't sure of the sizes |
176 | 0 | let this = mem::ManuallyDrop::new(self); |
177 | 0 | let ptr: *const Self::Output = (&*this as *const Self).cast(); |
178 | 0 | ptr::read(ptr) |
179 | 0 | } |
180 | 0 | } |
181 | | #[inline] |
182 | 0 | unsafe fn make(from: Self::Output) -> Self { |
183 | 0 | debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
184 | 0 | let from = mem::ManuallyDrop::new(from); |
185 | 0 | let ptr: *const Self = (&*from as *const Self::Output).cast(); |
186 | 0 | ptr::read(ptr) |
187 | 0 | } |
188 | | #[inline] |
189 | 0 | fn transform_mut<F>(&'a mut self, f: F) |
190 | 0 | where |
191 | 0 | F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
192 | 0 | { |
193 | 0 | unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
194 | 0 | } |
195 | | } |
196 | | |
197 | | /// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate |
198 | | #[allow(clippy::transmute_ptr_to_ptr)] |
199 | | unsafe impl<'a, K0, K1, V> Yokeable<'a> for ZeroMap2d<'static, K0, K1, V> |
200 | | where |
201 | | K0: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
202 | | K1: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
203 | | V: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
204 | | <K0 as ZeroMapKV<'static>>::Container: for<'b> Yokeable<'b>, |
205 | | <K1 as ZeroMapKV<'static>>::Container: for<'b> Yokeable<'b>, |
206 | | <V as ZeroMapKV<'static>>::Container: for<'b> Yokeable<'b>, |
207 | | { |
208 | | type Output = ZeroMap2d<'a, K0, K1, V>; |
209 | | #[inline] |
210 | 0 | fn transform(&'a self) -> &'a Self::Output { |
211 | 0 | unsafe { |
212 | 0 | // Unfortunately, because K and V are generic, rustc is |
213 | 0 | // unaware that these are covariant types, and cannot perform this cast automatically. |
214 | 0 | // We transmute it instead, and enforce the lack of a lifetime with the `K0, K1, V: 'static` bound |
215 | 0 | mem::transmute::<&Self, &Self::Output>(self) |
216 | 0 | } |
217 | 0 | } |
218 | | #[inline] |
219 | 0 | fn transform_owned(self) -> Self::Output { |
220 | 0 | debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
221 | | unsafe { |
222 | | // Similar problem as transform(), but we need to use ptr::read since |
223 | | // the compiler isn't sure of the sizes |
224 | 0 | let this = mem::ManuallyDrop::new(self); |
225 | 0 | let ptr: *const Self::Output = (&*this as *const Self).cast(); |
226 | 0 | ptr::read(ptr) |
227 | 0 | } |
228 | 0 | } |
229 | | #[inline] |
230 | 0 | unsafe fn make(from: Self::Output) -> Self { |
231 | 0 | debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
232 | 0 | let from = mem::ManuallyDrop::new(from); |
233 | 0 | let ptr: *const Self = (&*from as *const Self::Output).cast(); |
234 | 0 | ptr::read(ptr) |
235 | 0 | } |
236 | | #[inline] |
237 | 0 | fn transform_mut<F>(&'a mut self, f: F) |
238 | 0 | where |
239 | 0 | F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
240 | 0 | { |
241 | 0 | unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
242 | 0 | } |
243 | | } |
244 | | |
245 | | /// This impl requires enabling the optional `yoke` Cargo feature of the `zerovec` crate |
246 | | #[allow(clippy::transmute_ptr_to_ptr)] |
247 | | unsafe impl<'a, K0, K1, V> Yokeable<'a> for ZeroMap2dBorrowed<'static, K0, K1, V> |
248 | | where |
249 | | K0: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
250 | | K1: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
251 | | V: 'static + for<'b> ZeroMapKV<'b> + ?Sized, |
252 | | &'static <K0 as ZeroMapKV<'static>>::Slice: for<'b> Yokeable<'b>, |
253 | | &'static <K1 as ZeroMapKV<'static>>::Slice: for<'b> Yokeable<'b>, |
254 | | &'static <V as ZeroMapKV<'static>>::Slice: for<'b> Yokeable<'b>, |
255 | | { |
256 | | type Output = ZeroMap2dBorrowed<'a, K0, K1, V>; |
257 | | #[inline] |
258 | 0 | fn transform(&'a self) -> &'a Self::Output { |
259 | 0 | unsafe { |
260 | 0 | // Unfortunately, because K and V are generic, rustc is |
261 | 0 | // unaware that these are covariant types, and cannot perform this cast automatically. |
262 | 0 | // We transmute it instead, and enforce the lack of a lifetime with the `K0, K1, V: 'static` bound |
263 | 0 | mem::transmute::<&Self, &Self::Output>(self) |
264 | 0 | } |
265 | 0 | } |
266 | | #[inline] |
267 | 0 | fn transform_owned(self) -> Self::Output { |
268 | 0 | debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
269 | | unsafe { |
270 | | // Similar problem as transform(), but we need to use ptr::read since |
271 | | // the compiler isn't sure of the sizes |
272 | 0 | let this = mem::ManuallyDrop::new(self); |
273 | 0 | let ptr: *const Self::Output = (&*this as *const Self).cast(); |
274 | 0 | ptr::read(ptr) |
275 | 0 | } |
276 | 0 | } |
277 | | #[inline] |
278 | 0 | unsafe fn make(from: Self::Output) -> Self { |
279 | 0 | debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
280 | 0 | let from = mem::ManuallyDrop::new(from); |
281 | 0 | let ptr: *const Self = (&*from as *const Self::Output).cast(); |
282 | 0 | ptr::read(ptr) |
283 | 0 | } |
284 | | #[inline] |
285 | 0 | fn transform_mut<F>(&'a mut self, f: F) |
286 | 0 | where |
287 | 0 | F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
288 | 0 | { |
289 | 0 | unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
290 | 0 | } |
291 | | } |
292 | | |
293 | | #[cfg(test)] |
294 | | #[allow(non_camel_case_types, non_snake_case)] |
295 | | mod test { |
296 | | use super::*; |
297 | | use crate::{vecs::FlexZeroSlice, VarZeroSlice, ZeroSlice}; |
298 | | use databake::*; |
299 | | |
300 | | // Note: The following derives cover Yoke as well as Serde and databake. These may partially |
301 | | // duplicate tests elsewhere in this crate, but they are here for completeness. |
302 | | |
303 | | #[derive(yoke::Yokeable, zerofrom::ZeroFrom)] |
304 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
305 | | #[cfg_attr(feature = "databake", derive(databake::Bake), databake(path = zerovec::yoke_impls::test))] |
306 | | struct DeriveTest_ZeroVec<'data> { |
307 | | #[cfg_attr(feature = "serde", serde(borrow))] |
308 | | _data: ZeroVec<'data, u16>, |
309 | | } |
310 | | |
311 | | #[test] |
312 | | #[ignore] // https://github.com/rust-lang/rust/issues/98906 |
313 | | fn bake_ZeroVec() { |
314 | | test_bake!( |
315 | | DeriveTest_ZeroVec<'static>, |
316 | | crate::yoke_impls::test::DeriveTest_ZeroVec { |
317 | | _data: crate::ZeroVec::new(), |
318 | | }, |
319 | | zerovec, |
320 | | ); |
321 | | } |
322 | | |
323 | | #[derive(yoke::Yokeable)] |
324 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
325 | | #[cfg_attr(feature = "databake", derive(databake::Bake), databake(path = zerovec::yoke_impls::test))] |
326 | | struct DeriveTest_ZeroSlice<'data> { |
327 | | #[cfg_attr(feature = "serde", serde(borrow))] |
328 | | _data: &'data ZeroSlice<u16>, |
329 | | } |
330 | | |
331 | | #[test] |
332 | | fn bake_ZeroSlice() { |
333 | | test_bake!( |
334 | | DeriveTest_ZeroSlice<'static>, |
335 | | crate::yoke_impls::test::DeriveTest_ZeroSlice { |
336 | | _data: crate::ZeroSlice::new_empty(), |
337 | | }, |
338 | | zerovec, |
339 | | ); |
340 | | } |
341 | | |
342 | | #[derive(yoke::Yokeable, zerofrom::ZeroFrom)] |
343 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
344 | | #[cfg_attr(feature = "databake", derive(databake::Bake), databake(path = zerovec::yoke_impls::test))] |
345 | | struct DeriveTest_FlexZeroVec<'data> { |
346 | | #[cfg_attr(feature = "serde", serde(borrow))] |
347 | | _data: FlexZeroVec<'data>, |
348 | | } |
349 | | |
350 | | #[test] |
351 | | fn bake_FlexZeroVec() { |
352 | | test_bake!( |
353 | | DeriveTest_FlexZeroVec<'static>, |
354 | | crate::yoke_impls::test::DeriveTest_FlexZeroVec { |
355 | | _data: crate::vecs::FlexZeroVec::new(), |
356 | | }, |
357 | | zerovec, |
358 | | ); |
359 | | } |
360 | | |
361 | | #[derive(yoke::Yokeable)] |
362 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
363 | | #[cfg_attr(feature = "databake", derive(databake::Bake), databake(path = zerovec::yoke_impls::test))] |
364 | | struct DeriveTest_FlexZeroSlice<'data> { |
365 | | #[cfg_attr(feature = "serde", serde(borrow))] |
366 | | _data: &'data FlexZeroSlice, |
367 | | } |
368 | | |
369 | | #[test] |
370 | | fn bake_FlexZeroSlice() { |
371 | | test_bake!( |
372 | | DeriveTest_FlexZeroSlice<'static>, |
373 | | crate::yoke_impls::test::DeriveTest_FlexZeroSlice { |
374 | | _data: unsafe { crate::vecs::FlexZeroSlice::from_byte_slice_unchecked(b"\x01\0") }, |
375 | | }, |
376 | | zerovec, |
377 | | ); |
378 | | } |
379 | | |
380 | | #[derive(yoke::Yokeable, zerofrom::ZeroFrom)] |
381 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
382 | | #[cfg_attr(feature = "databake", derive(databake::Bake), databake(path = zerovec::yoke_impls::test))] |
383 | | struct DeriveTest_VarZeroVec<'data> { |
384 | | #[cfg_attr(feature = "serde", serde(borrow))] |
385 | | _data: VarZeroVec<'data, str>, |
386 | | } |
387 | | |
388 | | #[test] |
389 | | fn bake_VarZeroVec() { |
390 | | test_bake!( |
391 | | DeriveTest_VarZeroVec<'static>, |
392 | | crate::yoke_impls::test::DeriveTest_VarZeroVec { |
393 | | _data: crate::VarZeroVec::new(), |
394 | | }, |
395 | | zerovec, |
396 | | ); |
397 | | } |
398 | | |
399 | | #[derive(yoke::Yokeable)] |
400 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
401 | | #[cfg_attr(feature = "databake", derive(databake::Bake), databake(path = zerovec::yoke_impls::test))] |
402 | | struct DeriveTest_VarZeroSlice<'data> { |
403 | | #[cfg_attr(feature = "serde", serde(borrow))] |
404 | | _data: &'data VarZeroSlice<str>, |
405 | | } |
406 | | |
407 | | #[test] |
408 | | fn bake_VarZeroSlice() { |
409 | | test_bake!( |
410 | | DeriveTest_VarZeroSlice<'static>, |
411 | | crate::yoke_impls::test::DeriveTest_VarZeroSlice { |
412 | | _data: crate::VarZeroSlice::new_empty() |
413 | | }, |
414 | | zerovec, |
415 | | ); |
416 | | } |
417 | | |
418 | | #[derive(yoke::Yokeable, zerofrom::ZeroFrom)] |
419 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
420 | | #[cfg_attr(feature = "databake", derive(databake::Bake), databake(path = zerovec::yoke_impls::test))] |
421 | | #[yoke(prove_covariance_manually)] |
422 | | struct DeriveTest_ZeroMap<'data> { |
423 | | #[cfg_attr(feature = "serde", serde(borrow))] |
424 | | _data: ZeroMap<'data, [u8], str>, |
425 | | } |
426 | | |
427 | | #[test] |
428 | | fn bake_ZeroMap() { |
429 | | test_bake!( |
430 | | DeriveTest_ZeroMap<'static>, |
431 | | crate::yoke_impls::test::DeriveTest_ZeroMap { |
432 | | _data: unsafe { |
433 | | #[allow(unused_unsafe)] |
434 | | crate::ZeroMap::from_parts_unchecked( |
435 | | crate::VarZeroVec::new(), |
436 | | crate::VarZeroVec::new(), |
437 | | ) |
438 | | }, |
439 | | }, |
440 | | zerovec, |
441 | | ); |
442 | | } |
443 | | |
444 | | #[derive(yoke::Yokeable)] |
445 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
446 | | #[cfg_attr(feature = "databake", derive(databake::Bake), databake(path = zerovec::yoke_impls::test))] |
447 | | #[yoke(prove_covariance_manually)] |
448 | | struct DeriveTest_ZeroMapBorrowed<'data> { |
449 | | #[cfg_attr(feature = "serde", serde(borrow))] |
450 | | _data: ZeroMapBorrowed<'data, [u8], str>, |
451 | | } |
452 | | |
453 | | #[test] |
454 | | fn bake_ZeroMapBorrowed() { |
455 | | test_bake!( |
456 | | DeriveTest_ZeroMapBorrowed<'static>, |
457 | | crate::yoke_impls::test::DeriveTest_ZeroMapBorrowed { |
458 | | _data: unsafe { |
459 | | #[allow(unused_unsafe)] |
460 | | crate::maps::ZeroMapBorrowed::from_parts_unchecked( |
461 | | crate::VarZeroSlice::new_empty(), |
462 | | crate::VarZeroSlice::new_empty(), |
463 | | ) |
464 | | }, |
465 | | }, |
466 | | zerovec, |
467 | | ); |
468 | | } |
469 | | |
470 | | #[derive(yoke::Yokeable, zerofrom::ZeroFrom)] |
471 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
472 | | #[cfg_attr(feature = "databake", derive(databake::Bake), databake(path = zerovec::yoke_impls::test))] |
473 | | #[yoke(prove_covariance_manually)] |
474 | | struct DeriveTest_ZeroMapWithULE<'data> { |
475 | | #[cfg_attr(feature = "serde", serde(borrow))] |
476 | | _data: ZeroMap<'data, ZeroSlice<u32>, str>, |
477 | | } |
478 | | |
479 | | #[test] |
480 | | fn bake_ZeroMapWithULE() { |
481 | | test_bake!( |
482 | | DeriveTest_ZeroMapWithULE<'static>, |
483 | | crate::yoke_impls::test::DeriveTest_ZeroMapWithULE { |
484 | | _data: unsafe { |
485 | | #[allow(unused_unsafe)] |
486 | | crate::ZeroMap::from_parts_unchecked( |
487 | | crate::VarZeroVec::new(), |
488 | | crate::VarZeroVec::new(), |
489 | | ) |
490 | | }, |
491 | | }, |
492 | | zerovec, |
493 | | ); |
494 | | } |
495 | | |
496 | | #[derive(yoke::Yokeable, zerofrom::ZeroFrom)] |
497 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
498 | | #[cfg_attr(feature = "databake", derive(databake::Bake), databake(path = zerovec::yoke_impls::test))] |
499 | | #[yoke(prove_covariance_manually)] |
500 | | struct DeriveTest_ZeroMap2d<'data> { |
501 | | #[cfg_attr(feature = "serde", serde(borrow))] |
502 | | _data: ZeroMap2d<'data, u16, u16, str>, |
503 | | } |
504 | | |
505 | | #[test] |
506 | | fn bake_ZeroMap2d() { |
507 | | test_bake!( |
508 | | DeriveTest_ZeroMap2d<'static>, |
509 | | crate::yoke_impls::test::DeriveTest_ZeroMap2d { |
510 | | _data: unsafe { |
511 | | #[allow(unused_unsafe)] |
512 | | crate::ZeroMap2d::from_parts_unchecked( |
513 | | crate::ZeroVec::new(), |
514 | | crate::ZeroVec::new(), |
515 | | crate::ZeroVec::new(), |
516 | | crate::VarZeroVec::new(), |
517 | | ) |
518 | | }, |
519 | | }, |
520 | | zerovec, |
521 | | ); |
522 | | } |
523 | | |
524 | | #[derive(yoke::Yokeable)] |
525 | | #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] |
526 | | #[cfg_attr(feature = "databake", derive(databake::Bake), databake(path = zerovec::yoke_impls::test))] |
527 | | #[yoke(prove_covariance_manually)] |
528 | | struct DeriveTest_ZeroMap2dBorrowed<'data> { |
529 | | #[cfg_attr(feature = "serde", serde(borrow))] |
530 | | _data: ZeroMap2dBorrowed<'data, u16, u16, str>, |
531 | | } |
532 | | |
533 | | #[test] |
534 | | fn bake_ZeroMap2dBorrowed() { |
535 | | test_bake!( |
536 | | DeriveTest_ZeroMap2dBorrowed<'static>, |
537 | | crate::yoke_impls::test::DeriveTest_ZeroMap2dBorrowed { |
538 | | _data: unsafe { |
539 | | #[allow(unused_unsafe)] |
540 | | crate::maps::ZeroMap2dBorrowed::from_parts_unchecked( |
541 | | crate::ZeroSlice::new_empty(), |
542 | | crate::ZeroSlice::new_empty(), |
543 | | crate::ZeroSlice::new_empty(), |
544 | | crate::VarZeroSlice::new_empty(), |
545 | | ) |
546 | | }, |
547 | | }, |
548 | | zerovec, |
549 | | ); |
550 | | } |
551 | | } |