Debian Codegraph @

.cargo/vendor/cbindgen/tests/rust/transparent.rs

raw
1 struct DummyStruct;
2
3 // Transparent struct tuple wrapping a struct.
4 #[repr(transparent)]
5 struct TransparentComplexWrappingStructTuple(DummyStruct);
6
7 // Transparent struct tuple wrapping a primitive.
8 #[repr(transparent)]
9 struct TransparentPrimitiveWrappingStructTuple(u32);
10
11 // Transparent structure wrapping a struct.
12 #[repr(transparent)]
13 struct TransparentComplexWrappingStructure { only_field: DummyStruct }
14
15 // Transparent structure wrapping a primitive.
16 #[repr(transparent)]
17 struct TransparentPrimitiveWrappingStructure { only_field: u32 }
18
19 // Transparent struct wrapper with a marker wrapping a struct.
20 #[repr(transparent)]
21 struct TransparentComplexWrapper<T> {
22 only_non_zero_sized_field: DummyStruct,
23 marker: PhantomData<T>,
24 }
25
26 // Transparent struct wrapper with a marker wrapping a primitive.
27 #[repr(transparent)]
28 struct TransparentPrimitiveWrapper<T> {
29 only_non_zero_sized_field: u32,
30 marker: PhantomData<T>,
31 }
32
33 // Associated constant declared before struct declaration.
34 impl TransparentPrimitiveWithAssociatedConstants {
35 pub const ZERO: TransparentPrimitiveWithAssociatedConstants = TransparentPrimitiveWithAssociatedConstants {
36 bits: 0
37 };
38 }
39
40 // Transparent structure wrapping a primitive with associated constants.
41 #[repr(transparent)]
42 struct TransparentPrimitiveWithAssociatedConstants { bits: u32 }
43
44 // Associated constant declared after struct declaration.
45 impl TransparentPrimitiveWithAssociatedConstants {
46 pub const ONE: TransparentPrimitiveWithAssociatedConstants = TransparentPrimitiveWithAssociatedConstants {
47 bits: 1
48 };
49 }
50
51 enum EnumWithAssociatedConstantInImpl { A }
52
53 impl EnumWithAssociatedConstantInImpl {
54 pub const TEN: TransparentPrimitiveWrappingStructure = TransparentPrimitiveWrappingStructure { only_field: 10 };
55 }
56
57 #[no_mangle]
58 pub extern "C" fn root(
59 a: TransparentComplexWrappingStructTuple,
60 b: TransparentPrimitiveWrappingStructTuple,
61 c: TransparentComplexWrappingStructure,
62 d: TransparentPrimitiveWrappingStructure,
63 e: TransparentComplexWrapper<i32>,
64 f: TransparentPrimitiveWrapper<i32>,
65 g: TransparentPrimitiveWithAssociatedConstants,
66 h: EnumWithAssociatedConstantInImpl,
67 ) { }