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 #![allow(unused)]
6
7 use std::{borrow::Cow, marker::PhantomData};
8 use yoke::{Yoke, Yokeable};
9 use zerovec::{maps::ZeroMapKV, ule::AsULE, VarZeroVec, ZeroMap, ZeroVec};
10
11 #[derive(Yokeable)]
12 pub struct StringExample {
13 x: String,
14 }
15
16 #[derive(Yokeable, Copy, Clone)]
17 pub struct IntExample {
18 x: u32,
19 }
20
21 #[derive(Yokeable, Copy, Clone)]
22 pub struct GenericsExample<T> {
23 x: u32,
24 y: T,
25 }
26
27 #[derive(Yokeable, Copy, Clone)]
28 pub struct GenericsExampleWithDefault<T, U = usize> {
29 x: T,
30 y: U,
31 }
32
33 #[derive(Yokeable)]
34 pub struct CowExample<'a> {
35 x: u8,
36 y: &'a str,
37 z: Cow<'a, str>,
38 w: Cow<'a, [u8]>,
39 }
40
41 #[derive(Yokeable)]
42 pub struct ZeroVecExample<'a> {
43 var: VarZeroVec<'a, str>,
44 vec: ZeroVec<'a, u16>,
45 }
46
47 #[derive(Yokeable)]
48 pub struct ZeroVecExampleWithGenerics<'a, T: AsULE> {
49 gen: ZeroVec<'a, T>,
50 vec: ZeroVec<'a, u16>,
51 bare: T,
52 }
53
54 // Since ZeroMap has generic parameters, the Rust compiler cannot
55 // prove the covariance of the lifetimes. To use derive(Yokeable)
56 // with a type such as ZeroMap, you just add the attribute
57 // yoke(prove_covariance_manually)
58 #[derive(Yokeable)]
59 #[yoke(prove_covariance_manually)]
60 pub struct ZeroMapExample<'a> {
61 map: ZeroMap<'a, str, u16>,
62 }
63
64 #[derive(Yokeable)]
65 #[yoke(prove_covariance_manually)]
66 pub struct ZeroMapGenericExample<'a, T: for<'b> ZeroMapKV<'b> + ?Sized> {
67 map: ZeroMap<'a, str, T>,
68 }
69
70 #[derive(Yokeable)]
71 pub struct MaybeSizedWrap<T, Q: ?Sized, U: ?Sized> {
72 x: T,
73 y: Option<T>,
74 ignored: PhantomData<U>,
75 q: Q,
76 }
77
78 // TODO(#4119): Make this example compile
79 /*
80 #[derive(Yokeable)]
81 pub struct MaybeSizedWrapWithLifetime<'a, T, Q: ?Sized, U: ?Sized> {
82 x: T,
83 y: Option<T>,
84 ignored: &'a U,
85 q: Q,
86 }
87 */
88
89 pub struct AssertYokeable {
90 string: Yoke<StringExample, Box<[u8]>>,
91 int: Yoke<IntExample, Box<[u8]>>,
92 gen1: Yoke<GenericsExample<u32>, Box<[u8]>>,
93 gen2: Yoke<GenericsExample<String>, Box<[u8]>>,
94 gen_default1: Yoke<GenericsExampleWithDefault<String>, Box<[u8]>>,
95 gen_default2: Yoke<GenericsExampleWithDefault<String, u8>, Box<[u8]>>,
96 cow: Yoke<CowExample<'static>, Box<[u8]>>,
97 zv: Yoke<ZeroVecExample<'static>, Box<[u8]>>,
98 zv_gen1: Yoke<ZeroVecExampleWithGenerics<'static, u8>, Box<[u8]>>,
99 zv_gen2: Yoke<ZeroVecExampleWithGenerics<'static, char>, Box<[u8]>>,
100 map: Yoke<ZeroMapExample<'static>, Box<[u8]>>,
101 map_gen1: Yoke<ZeroMapGenericExample<'static, u32>, Box<[u8]>>,
102 map_gen2: Yoke<ZeroMapGenericExample<'static, str>, Box<[u8]>>,
103 maybe_sized_wrap: Yoke<MaybeSizedWrap<usize, usize, str>, Box<[u8]>>,
104 // TODO(#4119): Make this example compile
105 // maybe_sized_wrap_with_lt: Yoke<MaybeSizedWrapWithLifetime<'static, usize, usize, str>, Box<[u8]>>,
106 }
107
main()108 fn main() {}
109