Trait StableAbi
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§
const LAYOUT: &'static TypeLayout
const LAYOUT: &'static TypeLayout
The layout of the type provided by implementors.
Provided Associated Constants§
const ABI_CONSTS: AbiConsts = _
const ABI_CONSTS: AbiConsts = _
const-equivalents of the associated types.
Required Associated Types§
type 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".
Implementations on Foreign Types§
§impl StableAbi for PhantomPinned
impl StableAbi for PhantomPinned
const LAYOUT: &'static TypeLayout
type IsNonZeroType = False
§impl StableAbi for unsafe extern "C" fn()
impl StableAbi for unsafe extern "C" fn()
const LAYOUT: &'static TypeLayout
type IsNonZeroType = True
§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
§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
§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
§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
§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
§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
§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
§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
§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
§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
§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
§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
§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
§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
§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
§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
§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
§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
§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
§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
§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
§impl<T0, T1> StableAbi for PhantomData<(T0, T1)>
impl<T0, T1> StableAbi for PhantomData<(T0, T1)>
const LAYOUT: &'static TypeLayout
type IsNonZeroType = False
§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
§impl<T, const N: usize> StableAbi for [T; N]where
T: StableAbi,
impl<T, const N: usize> StableAbi for [T; N]where
T: StableAbi,
const LAYOUT: &'static TypeLayout
type IsNonZeroType = False
§impl<T> StableAbi for *const Twhere
T: StableAbi,
impl<T> StableAbi for *const Twhere
T: StableAbi,
const LAYOUT: &'static TypeLayout
type IsNonZeroType = False
§impl<T> StableAbi for *mut Twhere
T: StableAbi,
impl<T> StableAbi for *mut Twhere
T: StableAbi,
const LAYOUT: &'static TypeLayout
type IsNonZeroType = False
§impl<T> StableAbi for Atomic<*mut T>where
T: StableAbi,
impl<T> StableAbi for Atomic<*mut T>where
T: StableAbi,
const LAYOUT: &'static TypeLayout
type IsNonZeroType = False
§impl<T> StableAbi for MaybeUninit<T>where
T: StableAbi,
impl<T> StableAbi for MaybeUninit<T>where
T: StableAbi,
const LAYOUT: &'static TypeLayout
type IsNonZeroType = False
§impl<T> StableAbi for NonNull<T>where
T: StableAbi,
impl<T> StableAbi for NonNull<T>where
T: StableAbi,
const LAYOUT: &'static TypeLayout
type IsNonZeroType = True
§impl<T> StableAbi for Option<T>where
T: StableAbi<IsNonZeroType = True>,
Implementing abi stability for Option<T> is fine if
T is a NonZero primitive type.
impl<T> StableAbi for Option<T>where
T: StableAbi<IsNonZeroType = True>,
Implementing abi stability for Option<T> is fine if
T is a NonZero primitive type.