cxx/
opaque.rs

1#![allow(missing_docs)]
2
3use crate::void;
4use core::cell::UnsafeCell;
5use core::marker::{PhantomData, PhantomPinned};
6use core::mem;
7use core::panic::RefUnwindSafe;
8
9// . size = 0
10// . align = 1
11// . ffi-safe
12// . !Send
13// . !Sync
14// . !Unpin
15// . not readonly
16// . unwind-safe
17#[repr(C, packed)]
18pub struct Opaque {
19    _private: [*const void; 0],
20    _pinned: PhantomData<PhantomPinned>,
21    _mutable: SyncUnsafeCell<PhantomData<()>>,
22}
23
24impl RefUnwindSafe for Opaque {}
25
26// TODO: https://github.com/rust-lang/rust/issues/95439
27#[repr(transparent)]
28struct SyncUnsafeCell<T>(UnsafeCell<T>);
29
30unsafe impl<T> Sync for SyncUnsafeCell<T> {}
31
32const_assert_eq!(0, mem::size_of::<Opaque>());
33const_assert_eq!(1, mem::align_of::<Opaque>());