| 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 |
use zerovec::ule::{AsULE, VarULE}; |
| 6 |
|
| 7 |
// https://github.com/unicode-org/icu4x/issues/6723 |
| 8 |
#[zerovec::make_varule(CustomVarULE)] |
| 9 |
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] |
| 10 |
struct CustomVar<'a> { |
| 11 |
a: u32, |
| 12 |
b: &'a str, |
| 13 |
} |
| 14 |
|
| 15 |
#[test] |
| 16 |
fn test_make_varule_from_bytes_unchecked_miri() { |
| 17 |
// https://github.com/unicode-org/icu4x/issues/6723 |
| 18 |
let custom = CustomVar { a: 12345, b: "x" }; |
| 19 |
let boxed: Box<CustomVarULE> = zerovec::ule::encode_varule_to_box(&custom); |
| 20 |
let bytes = boxed.as_bytes(); |
| 21 |
let ule = unsafe { CustomVarULE::from_bytes_unchecked(bytes) }; |
| 22 |
assert_eq!(u32::from_unaligned(ule.a), 12345); |
| 23 |
assert_eq!(&ule.b, "x"); |
| 24 |
} |