pub unsafe trait StableAbi: GetStaticEquivalent_ {
type IsNonZeroType: Boolean;
const LAYOUT: &'static TypeLayout;
const ABI_CONSTS: AbiConsts = _;
}
Expand description
Represents a type whose layout is stable.
This trait can be derived using
#[derive(StableAbi)]
.
§Safety
The layout specified in LAYOUT
must be correct,
otherwise type checking when loading a dynamic library would be unsound,
and passing this into a dynamic library would be equivalent to transmuting it.
§Caveats
This trait cannot be directly implemented for functions that take lifetime parameters,
because of that, #[derive(StableAbi)]
detects the presence of extern fn
types in type definitions.
Required Associated Constants§
Sourceconst LAYOUT: &'static TypeLayout
const LAYOUT: &'static TypeLayout
The layout of the type provided by implementors.
Provided Associated Constants§
Sourceconst ABI_CONSTS: AbiConsts = _
const ABI_CONSTS: AbiConsts = _
const
-equivalents of the associated types.
Required Associated Types§
Sourcetype IsNonZeroType: Boolean
type IsNonZeroType: Boolean
Whether this type has a single invalid bit-pattern.
Some standard library types have a single value that is invalid for them eg:0,null.
these types are the only ones which can be stored in a Option<_>
that implements StableAbi.
For an alternative to Option<T>
for types where
IsNonZeroType = False
, you can use ROption
.
Non-exhaustive list of std types that are NonZero:
-
&T
(any T). -
&mut T
(any T). -
extern "C" fn()
. -
std::ptr::NonNull
-
std::num::NonZero*
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl StableAbi for Void
impl StableAbi for Void
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for c_void
impl StableAbi for c_void
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for bool
impl StableAbi for bool
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for f32
impl StableAbi for f32
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for f64
impl StableAbi for f64
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for i8
impl StableAbi for i8
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for i16
impl StableAbi for i16
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for i32
impl StableAbi for i32
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for i64
impl StableAbi for i64
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for isize
impl StableAbi for isize
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for u8
impl StableAbi for u8
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for u16
impl StableAbi for u16
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for u32
impl StableAbi for u32
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for u64
impl StableAbi for u64
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for ()
impl StableAbi for ()
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for usize
impl StableAbi for usize
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for PhantomPinned
impl StableAbi for PhantomPinned
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for AtomicBool
impl StableAbi for AtomicBool
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for AtomicI8
impl StableAbi for AtomicI8
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for AtomicI16
impl StableAbi for AtomicI16
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for AtomicI32
impl StableAbi for AtomicI32
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for AtomicI64
impl StableAbi for AtomicI64
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for AtomicIsize
impl StableAbi for AtomicIsize
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for AtomicU8
impl StableAbi for AtomicU8
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for AtomicU16
impl StableAbi for AtomicU16
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for AtomicU32
impl StableAbi for AtomicU32
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for AtomicU64
impl StableAbi for AtomicU64
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for AtomicUsize
impl StableAbi for AtomicUsize
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl StableAbi for NonZeroI8
impl StableAbi for NonZeroI8
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl StableAbi for NonZeroI16
impl StableAbi for NonZeroI16
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl StableAbi for NonZeroI32
impl StableAbi for NonZeroI32
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl StableAbi for NonZeroI64
impl StableAbi for NonZeroI64
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl StableAbi for NonZeroIsize
impl StableAbi for NonZeroIsize
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl StableAbi for NonZeroU8
impl StableAbi for NonZeroU8
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl StableAbi for NonZeroU16
impl StableAbi for NonZeroU16
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl StableAbi for NonZeroU32
impl StableAbi for NonZeroU32
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl StableAbi for NonZeroU64
impl StableAbi for NonZeroU64
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl StableAbi for NonZeroUsize
impl StableAbi for NonZeroUsize
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl StableAbi for extern "C" fn()
impl StableAbi for extern "C" fn()
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl StableAbi for unsafe extern "C" fn()
impl StableAbi for unsafe extern "C" fn()
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl<'a, T> StableAbi for &'a Twhere
T: 'a + StableAbi,
impl<'a, T> StableAbi for &'a Twhere
T: 'a + StableAbi,
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl<'a, T> StableAbi for &'a mut Twhere
T: 'a + StableAbi,
impl<'a, T> StableAbi for &'a mut Twhere
T: 'a + StableAbi,
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = True
Source§impl<P> StableAbi for Cell<P>where
P: StableAbi,
impl<P> StableAbi for Cell<P>where
P: StableAbi,
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<P> StableAbi for UnsafeCell<P>where
P: StableAbi,
impl<P> StableAbi for UnsafeCell<P>where
P: StableAbi,
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<P> StableAbi for ManuallyDrop<P>where
P: StableAbi,
impl<P> StableAbi for ManuallyDrop<P>where
P: StableAbi,
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = <P as StableAbi>::IsNonZeroType
Source§impl<P> StableAbi for Wrapping<P>where
P: StableAbi,
impl<P> StableAbi for Wrapping<P>where
P: StableAbi,
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = <P as StableAbi>::IsNonZeroType
Source§impl<P> StableAbi for Pin<P>where
P: StableAbi,
impl<P> StableAbi for Pin<P>where
P: StableAbi,
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = <P as StableAbi>::IsNonZeroType
Source§impl<T0> StableAbi for PhantomData<(T0,)>where
T0: StableAbi,
impl<T0> StableAbi for PhantomData<(T0,)>where
T0: StableAbi,
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1> StableAbi for PhantomData<(T0, T1)>
impl<T0, T1> StableAbi for PhantomData<(T0, T1)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2> StableAbi for PhantomData<(T0, T1, T2)>
impl<T0, T1, T2> StableAbi for PhantomData<(T0, T1, T2)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3> StableAbi for PhantomData<(T0, T1, T2, T3)>
impl<T0, T1, T2, T3> StableAbi for PhantomData<(T0, T1, T2, T3)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3, T4> StableAbi for PhantomData<(T0, T1, T2, T3, T4)>
impl<T0, T1, T2, T3, T4> StableAbi for PhantomData<(T0, T1, T2, T3, T4)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3, T4, T5> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5)>
impl<T0, T1, T2, T3, T4, T5> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3, T4, T5, T6> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6)>
impl<T0, T1, T2, T3, T4, T5, T6> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7)>
impl<T0, T1, T2, T3, T4, T5, T6, T7> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8)>
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)>
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)>
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)>
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)>
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)>
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)>
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> StableAbi for PhantomData<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15)>
const LAYOUT: &'static TypeLayout = _
type IsNonZeroType = False
Source§impl<T> StableAbi for Option<T>
impl<T> StableAbi for Option<T>
Implementing abi stability for Option<T>
is fine if
T is a NonZero primitive type.