| 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 |
fn transform(&'a self) -> &'a Self::Output { |
| 27 |
self |
| 28 |
} |
| 29 |
#[inline] |
| 30 |
fn transform_owned(self) -> Self::Output { |
| 31 |
self |
| 32 |
} |
| 33 |
#[inline] |
| 34 |
unsafe fn make(from: Self::Output) -> Self { |
| 35 |
debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
| 36 |
let from = mem::ManuallyDrop::new(from); |
| 37 |
let ptr: *const Self = (&*from as *const Self::Output).cast(); |
| 38 |
ptr::read(ptr) |
| 39 |
} |
| 40 |
#[inline] |
| 41 |
fn transform_mut<F>(&'a mut self, f: F) |
| 42 |
where |
| 43 |
F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
| 44 |
{ |
| 45 |
unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
| 46 |
} |
| 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 |
fn transform(&'a self) -> &'a Self::Output { |
| 55 |
self |
| 56 |
} |
| 57 |
#[inline] |
| 58 |
fn transform_owned(self) -> Self::Output { |
| 59 |
self |
| 60 |
} |
| 61 |
#[inline] |
| 62 |
unsafe fn make(from: Self::Output) -> Self { |
| 63 |
debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
| 64 |
let from = mem::ManuallyDrop::new(from); |
| 65 |
let ptr: *const Self = (&*from as *const Self::Output).cast(); |
| 66 |
ptr::read(ptr) |
| 67 |
} |
| 68 |
#[inline] |
| 69 |
fn transform_mut<F>(&'a mut self, f: F) |
| 70 |
where |
| 71 |
F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
| 72 |
{ |
| 73 |
unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
| 74 |
} |
| 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 |
fn transform(&'a self) -> &'a Self::Output { |
| 83 |
self |
| 84 |
} |
| 85 |
#[inline] |
| 86 |
fn transform_owned(self) -> Self::Output { |
| 87 |
self |
| 88 |
} |
| 89 |
#[inline] |
| 90 |
unsafe fn make(from: Self::Output) -> Self { |
| 91 |
debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
| 92 |
let from = mem::ManuallyDrop::new(from); |
| 93 |
let ptr: *const Self = (&*from as *const Self::Output).cast(); |
| 94 |
ptr::read(ptr) |
| 95 |
} |
| 96 |
#[inline] |
| 97 |
fn transform_mut<F>(&'a mut self, f: F) |
| 98 |
where |
| 99 |
F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
| 100 |
{ |
| 101 |
unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
| 102 |
} |
| 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 |
fn transform(&'a self) -> &'a Self::Output { |
| 117 |
unsafe { |
| 118 |
// Unfortunately, because K and V are generic, rustc is |
| 119 |
// unaware that these are covariant types, and cannot perform this cast automatically. |
| 120 |
// We transmute it instead, and enforce the lack of a lifetime with the `K, V: 'static` bound |
| 121 |
mem::transmute::<&Self, &Self::Output>(self) |
| 122 |
} |
| 123 |
} |
| 124 |
#[inline] |
| 125 |
fn transform_owned(self) -> Self::Output { |
| 126 |
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 |
let this = mem::ManuallyDrop::new(self); |
| 131 |
let ptr: *const Self::Output = (&*this as *const Self).cast(); |
| 132 |
ptr::read(ptr) |
| 133 |
} |
| 134 |
} |
| 135 |
#[inline] |
| 136 |
unsafe fn make(from: Self::Output) -> Self { |
| 137 |
debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
| 138 |
let from = mem::ManuallyDrop::new(from); |
| 139 |
let ptr: *const Self = (&*from as *const Self::Output).cast(); |
| 140 |
ptr::read(ptr) |
| 141 |
} |
| 142 |
#[inline] |
| 143 |
fn transform_mut<F>(&'a mut self, f: F) |
| 144 |
where |
| 145 |
F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
| 146 |
{ |
| 147 |
unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
| 148 |
} |
| 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 |
fn transform(&'a self) -> &'a Self::Output { |
| 163 |
unsafe { |
| 164 |
// Unfortunately, because K and V are generic, rustc is |
| 165 |
// unaware that these are covariant types, and cannot perform this cast automatically. |
| 166 |
// We transmute it instead, and enforce the lack of a lifetime with the `K, V: 'static` bound |
| 167 |
mem::transmute::<&Self, &Self::Output>(self) |
| 168 |
} |
| 169 |
} |
| 170 |
#[inline] |
| 171 |
fn transform_owned(self) -> Self::Output { |
| 172 |
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 |
let this = mem::ManuallyDrop::new(self); |
| 177 |
let ptr: *const Self::Output = (&*this as *const Self).cast(); |
| 178 |
ptr::read(ptr) |
| 179 |
} |
| 180 |
} |
| 181 |
#[inline] |
| 182 |
unsafe fn make(from: Self::Output) -> Self { |
| 183 |
debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
| 184 |
let from = mem::ManuallyDrop::new(from); |
| 185 |
let ptr: *const Self = (&*from as *const Self::Output).cast(); |
| 186 |
ptr::read(ptr) |
| 187 |
} |
| 188 |
#[inline] |
| 189 |
fn transform_mut<F>(&'a mut self, f: F) |
| 190 |
where |
| 191 |
F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
| 192 |
{ |
| 193 |
unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
| 194 |
} |
| 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 |
fn transform(&'a self) -> &'a Self::Output { |
| 211 |
unsafe { |
| 212 |
// Unfortunately, because K and V are generic, rustc is |
| 213 |
// unaware that these are covariant types, and cannot perform this cast automatically. |
| 214 |
// We transmute it instead, and enforce the lack of a lifetime with the `K0, K1, V: 'static` bound |
| 215 |
mem::transmute::<&Self, &Self::Output>(self) |
| 216 |
} |
| 217 |
} |
| 218 |
#[inline] |
| 219 |
fn transform_owned(self) -> Self::Output { |
| 220 |
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 |
let this = mem::ManuallyDrop::new(self); |
| 225 |
let ptr: *const Self::Output = (&*this as *const Self).cast(); |
| 226 |
ptr::read(ptr) |
| 227 |
} |
| 228 |
} |
| 229 |
#[inline] |
| 230 |
unsafe fn make(from: Self::Output) -> Self { |
| 231 |
debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
| 232 |
let from = mem::ManuallyDrop::new(from); |
| 233 |
let ptr: *const Self = (&*from as *const Self::Output).cast(); |
| 234 |
ptr::read(ptr) |
| 235 |
} |
| 236 |
#[inline] |
| 237 |
fn transform_mut<F>(&'a mut self, f: F) |
| 238 |
where |
| 239 |
F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
| 240 |
{ |
| 241 |
unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
| 242 |
} |
| 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 |
fn transform(&'a self) -> &'a Self::Output { |
| 259 |
unsafe { |
| 260 |
// Unfortunately, because K and V are generic, rustc is |
| 261 |
// unaware that these are covariant types, and cannot perform this cast automatically. |
| 262 |
// We transmute it instead, and enforce the lack of a lifetime with the `K0, K1, V: 'static` bound |
| 263 |
mem::transmute::<&Self, &Self::Output>(self) |
| 264 |
} |
| 265 |
} |
| 266 |
#[inline] |
| 267 |
fn transform_owned(self) -> Self::Output { |
| 268 |
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 |
let this = mem::ManuallyDrop::new(self); |
| 273 |
let ptr: *const Self::Output = (&*this as *const Self).cast(); |
| 274 |
ptr::read(ptr) |
| 275 |
} |
| 276 |
} |
| 277 |
#[inline] |
| 278 |
unsafe fn make(from: Self::Output) -> Self { |
| 279 |
debug_assert!(mem::size_of::<Self::Output>() == mem::size_of::<Self>()); |
| 280 |
let from = mem::ManuallyDrop::new(from); |
| 281 |
let ptr: *const Self = (&*from as *const Self::Output).cast(); |
| 282 |
ptr::read(ptr) |
| 283 |
} |
| 284 |
#[inline] |
| 285 |
fn transform_mut<F>(&'a mut self, f: F) |
| 286 |
where |
| 287 |
F: 'static + for<'b> FnOnce(&'b mut Self::Output), |
| 288 |
{ |
| 289 |
unsafe { f(mem::transmute::<&mut Self, &mut Self::Output>(self)) } |
| 290 |
} |
| 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 |
} |