const_type_layout/impls/core/
mem.rs

1use crate::{
2    typeset::{tset, ComputeTypeSet, ExpandTypeSet},
3    Field, MaybeUninhabited, TypeLayout, TypeLayoutInfo, TypeStructure,
4};
5
6unsafe impl<T: TypeLayout> TypeLayout for core::mem::ManuallyDrop<T> {
7    type Inhabited = T::Inhabited;
8
9    const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
10        name: ::core::any::type_name::<Self>(),
11        size: ::core::mem::size_of::<Self>(),
12        alignment: ::core::mem::align_of::<Self>(),
13        structure: TypeStructure::Struct {
14            repr: "transparent",
15            fields: &[Field {
16                name: "value",
17                offset: MaybeUninhabited::new::<T>(0),
18                ty: ::core::any::type_name::<T>(),
19            }],
20        },
21    };
22}
23
24unsafe impl<T: ComputeTypeSet> ComputeTypeSet for core::mem::ManuallyDrop<T> {
25    type Output<R: ExpandTypeSet> = tset![T, .. @ R];
26}
27
28unsafe impl<T: TypeLayout> TypeLayout for core::mem::MaybeUninit<T> {
29    type Inhabited = crate::inhabited::Inhabited;
30
31    const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
32        name: ::core::any::type_name::<Self>(),
33        size: ::core::mem::size_of::<Self>(),
34        alignment: ::core::mem::align_of::<Self>(),
35        structure: TypeStructure::Union {
36            repr: "transparent",
37            fields: &[
38                Field {
39                    name: "uninit",
40                    offset: MaybeUninhabited::Inhabited(0),
41                    ty: ::core::any::type_name::<()>(),
42                },
43                Field {
44                    name: "value",
45                    offset: MaybeUninhabited::new::<T>(0),
46                    ty: ::core::any::type_name::<core::mem::ManuallyDrop<T>>(),
47                },
48            ],
49        },
50    };
51}
52
53unsafe impl<T: ComputeTypeSet> ComputeTypeSet for core::mem::MaybeUninit<T> {
54    type Output<R: ExpandTypeSet> = tset![(), core::mem::ManuallyDrop<T>, .. @ R];
55}
56
57unsafe impl<T> TypeLayout for core::mem::Discriminant<T> {
58    type Inhabited = crate::inhabited::Inhabited;
59
60    const TYPE_LAYOUT: TypeLayoutInfo<'static> = TypeLayoutInfo {
61        name: ::core::any::type_name::<Self>(),
62        size: ::core::mem::size_of::<Self>(),
63        alignment: ::core::mem::align_of::<Self>(),
64        structure: TypeStructure::Struct {
65            repr: "",
66            fields: &[Field {
67                name: "0",
68                offset: MaybeUninhabited::new::<Self>(0),
69                ty: ::core::any::type_name::<<Self as crate::ExtractDiscriminant>::Discriminant>(),
70            }],
71        },
72    };
73}
74
75unsafe impl<T> ComputeTypeSet for core::mem::Discriminant<T> {
76    type Output<R: ExpandTypeSet> =
77        tset![<Self as crate::ExtractDiscriminant>::Discriminant, .. @ R];
78}