From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../rust/yoke-derive/examples/yoke_derive.rs | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 third_party/rust/yoke-derive/examples/yoke_derive.rs (limited to 'third_party/rust/yoke-derive/examples') diff --git a/third_party/rust/yoke-derive/examples/yoke_derive.rs b/third_party/rust/yoke-derive/examples/yoke_derive.rs new file mode 100644 index 0000000000..a011d5c241 --- /dev/null +++ b/third_party/rust/yoke-derive/examples/yoke_derive.rs @@ -0,0 +1,86 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +#![allow(unused)] + +use std::borrow::Cow; +use yoke::{Yoke, Yokeable}; +use zerovec::{maps::ZeroMapKV, ule::AsULE, VarZeroVec, ZeroMap, ZeroVec}; + +#[derive(Yokeable)] +pub struct StringExample { + x: String, +} + +#[derive(Yokeable, Copy, Clone)] +pub struct IntExample { + x: u32, +} + +#[derive(Yokeable, Copy, Clone)] +pub struct GenericsExample { + x: u32, + y: T, +} + +#[derive(Yokeable, Copy, Clone)] +pub struct GenericsExampleWithDefault { + x: T, + y: U, +} + +#[derive(Yokeable)] +pub struct CowExample<'a> { + x: u8, + y: &'a str, + z: Cow<'a, str>, + w: Cow<'a, [u8]>, +} + +#[derive(Yokeable)] +pub struct ZeroVecExample<'a> { + var: VarZeroVec<'a, str>, + vec: ZeroVec<'a, u16>, +} + +#[derive(Yokeable)] +pub struct ZeroVecExampleWithGenerics<'a, T: AsULE> { + gen: ZeroVec<'a, T>, + vec: ZeroVec<'a, u16>, + bare: T, +} + +// Since ZeroMap has generic parameters, the Rust compiler cannot +// prove the covariance of the lifetimes. To use derive(Yokeable) +// with a type such as ZeroMap, you just add the attribute +// yoke(prove_covariance_manually) +#[derive(Yokeable)] +#[yoke(prove_covariance_manually)] +pub struct ZeroMapExample<'a> { + map: ZeroMap<'a, str, u16>, +} + +#[derive(Yokeable)] +#[yoke(prove_covariance_manually)] +pub struct ZeroMapGenericExample<'a, T: for<'b> ZeroMapKV<'b> + ?Sized> { + map: ZeroMap<'a, str, T>, +} + +pub struct AssertYokeable { + string: Yoke>, + int: Yoke>, + gen1: Yoke, Box<[u8]>>, + gen2: Yoke, Box<[u8]>>, + gen_default1: Yoke, Box<[u8]>>, + gen_default2: Yoke, Box<[u8]>>, + cow: Yoke, Box<[u8]>>, + zv: Yoke, Box<[u8]>>, + zv_gen1: Yoke, Box<[u8]>>, + zv_gen2: Yoke, Box<[u8]>>, + map: Yoke, Box<[u8]>>, + map_gen1: Yoke, Box<[u8]>>, + map_gen2: Yoke, Box<[u8]>>, +} + +fn main() {} -- cgit v1.2.3