abi_stable/
marker_type.rs1use std::{cell::Cell, marker::PhantomData, rc::Rc};
4
5use crate::{
6 abi_stability::PrefixStableAbi,
7 derive_macro_reexports::*,
8 type_layout::{GenericTLData, MonoTLData, MonoTypeLayout, ReprAttr, TypeLayout},
9};
10
11#[macro_use]
12mod stable_abi_impls;
13
14#[repr(C)]
18#[derive(StableAbi)]
19pub struct SyncSend;
20
21const _: () = zst_assert! {SyncSend};
22
23pub struct UnsyncUnsend {
27 _marker: UnsafeIgnoredType<Rc<()>>,
28}
29
30monomorphic_marker_type! {UnsyncUnsend, UnsafeIgnoredType<Rc<()>>}
31
32impl UnsyncUnsend {
33 pub const NEW: Self = Self {
35 _marker: UnsafeIgnoredType::NEW,
36 };
37}
38
39pub struct UnsyncSend {
43 _marker: UnsafeIgnoredType<Cell<()>>,
44}
45
46monomorphic_marker_type! {UnsyncSend, UnsafeIgnoredType<Cell<()>>}
47
48impl UnsyncSend {
49 pub const NEW: Self = Self {
51 _marker: UnsafeIgnoredType::NEW,
52 };
53}
54
55pub struct SyncUnsend {
60 _marker: UnsyncUnsend,
61}
62
63monomorphic_marker_type! {SyncUnsend, UnsyncUnsend}
64
65impl SyncUnsend {
66 pub const NEW: Self = Self {
68 _marker: UnsyncUnsend::NEW,
69 };
70}
71
72unsafe impl Sync for SyncUnsend {}
73
74#[repr(C)]
80#[derive(StableAbi)]
81pub struct NotCopyNotClone;
83
84const _: () = zst_assert! {NotCopyNotClone};
85
86#[repr(C)]
91#[derive(StableAbi)]
92pub struct ErasedObject<T = ()> {
93 _marker: NonOwningPhantom<T>,
94}
95
96const _: () = zst_assert! {ErasedObject};
97
98pub struct ErasedPrefix {
103 _priv: PhantomData<u8>,
104}
105
106const _: () = zst_assert!(ErasedPrefix);
107
108unsafe impl GetStaticEquivalent_ for ErasedPrefix {
109 type StaticEquivalent = ErasedPrefix;
110}
111
112unsafe impl PrefixStableAbi for ErasedPrefix {
113 type IsNonZeroType = False;
114 const LAYOUT: &'static TypeLayout = <ErasedObject as StableAbi>::LAYOUT;
115}
116
117pub struct UnsafeIgnoredType<T: ?Sized> {
132 pub _inner: PhantomData<T>,
136}
137
138impl<T: ?Sized> UnsafeIgnoredType<T> {
139 pub const DEFAULT: Self = Self {
141 _inner: PhantomData,
142 };
143
144 pub const NEW: Self = Self {
146 _inner: PhantomData,
147 };
148}
149
150impl<T: ?Sized> Copy for UnsafeIgnoredType<T> {}
151
152impl<T: ?Sized> Default for UnsafeIgnoredType<T> {
153 fn default() -> Self {
154 Self::DEFAULT
155 }
156}
157
158impl<T: ?Sized> Clone for UnsafeIgnoredType<T> {
159 fn clone(&self) -> Self {
160 *self
161 }
162}
163
164unsafe impl<T> GetStaticEquivalent_ for UnsafeIgnoredType<T> {
165 type StaticEquivalent = ();
166}
167unsafe impl<T> StableAbi for UnsafeIgnoredType<T> {
168 type IsNonZeroType = False;
169
170 const LAYOUT: &'static TypeLayout = {
171 const MONO_TYPE_LAYOUT: &MonoTypeLayout = &MonoTypeLayout::new(
172 *mono_shared_vars,
173 rstr!("UnsafeIgnoredType"),
174 make_item_info!(),
175 MonoTLData::struct_(rslice![]),
176 tl_genparams!(;;),
177 ReprAttr::C,
178 ModReflMode::Module,
179 rslice![],
180 );
181
182 make_shared_vars! {
183 impl[T] UnsafeIgnoredType<T>;
184
185 let (mono_shared_vars,shared_vars)={};
186 }
187
188 zst_assert!(Self);
189
190 &TypeLayout::from_std::<Self>(
191 shared_vars,
192 MONO_TYPE_LAYOUT,
193 Self::ABI_CONSTS,
194 GenericTLData::Struct,
195 )
196 };
197}
198
199pub struct NonOwningPhantom<T: ?Sized> {
203 _marker: PhantomData<extern "C" fn() -> T>,
206}
207
208impl<T: ?Sized> NonOwningPhantom<T> {
209 pub const DEFAULT: Self = Self {
211 _marker: PhantomData,
212 };
213
214 pub const NEW: Self = Self {
216 _marker: PhantomData,
217 };
218}
219
220impl<T: ?Sized> Copy for NonOwningPhantom<T> {}
221
222impl<T: ?Sized> Default for NonOwningPhantom<T> {
223 #[inline(always)]
224 fn default() -> Self {
225 Self::DEFAULT
226 }
227}
228
229impl<T: ?Sized> Clone for NonOwningPhantom<T> {
230 #[inline(always)]
231 fn clone(&self) -> Self {
232 *self
233 }
234}
235
236unsafe impl<T: ?Sized> GetStaticEquivalent_ for NonOwningPhantom<T>
237where
238 PhantomData<T>: GetStaticEquivalent_,
239{
240 type StaticEquivalent = GetStaticEquivalent<PhantomData<T>>;
241}
242
243unsafe impl<T: ?Sized> StableAbi for NonOwningPhantom<T>
244where
245 PhantomData<T>: StableAbi,
246{
247 type IsNonZeroType = False;
248
249 const LAYOUT: &'static TypeLayout = {
250 zst_assert!(Self);
251 <PhantomData<T> as StableAbi>::LAYOUT
252 };
253}