Trait abi_stable::abi_stability::stable_abi_trait::StableAbi
source · 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 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*
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.
Object Safety§
Implementations on Foreign Types§
source§impl StableAbi for Void
impl StableAbi for Void
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for c_void
impl StableAbi for c_void
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for bool
impl StableAbi for bool
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for f32
impl StableAbi for f32
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for f64
impl StableAbi for f64
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for i8
impl StableAbi for i8
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for i16
impl StableAbi for i16
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for i32
impl StableAbi for i32
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for i64
impl StableAbi for i64
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for isize
impl StableAbi for isize
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for u8
impl StableAbi for u8
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for u16
impl StableAbi for u16
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for u32
impl StableAbi for u32
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for u64
impl StableAbi for u64
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for ()
impl StableAbi for ()
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for usize
impl StableAbi for usize
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for PhantomPinned
impl StableAbi for PhantomPinned
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for AtomicBool
impl StableAbi for AtomicBool
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for AtomicI8
impl StableAbi for AtomicI8
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for AtomicI16
impl StableAbi for AtomicI16
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for AtomicI32
impl StableAbi for AtomicI32
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for AtomicI64
impl StableAbi for AtomicI64
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for AtomicIsize
impl StableAbi for AtomicIsize
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for AtomicU8
impl StableAbi for AtomicU8
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for AtomicU16
impl StableAbi for AtomicU16
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for AtomicU32
impl StableAbi for AtomicU32
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for AtomicU64
impl StableAbi for AtomicU64
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for AtomicUsize
impl StableAbi for AtomicUsize
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for NonZeroI8
impl StableAbi for NonZeroI8
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for NonZeroI16
impl StableAbi for NonZeroI16
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for NonZeroI32
impl StableAbi for NonZeroI32
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for NonZeroI64
impl StableAbi for NonZeroI64
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for NonZeroIsize
impl StableAbi for NonZeroIsize
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for NonZeroU8
impl StableAbi for NonZeroU8
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for NonZeroU16
impl StableAbi for NonZeroU16
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for NonZeroU32
impl StableAbi for NonZeroU32
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for NonZeroU64
impl StableAbi for NonZeroU64
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for NonZeroUsize
impl StableAbi for NonZeroUsize
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for extern "C" fn()
impl StableAbi for extern "C" fn()
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl StableAbi for unsafe extern "C" fn()
impl StableAbi for unsafe extern "C" fn()
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl<'a, T> StableAbi for &'a Twhere
T: 'a + StableAbi,
impl<'a, T> StableAbi for &'a Twhere
T: 'a + StableAbi,
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl<'a, T> StableAbi for &'a mut Twhere
T: 'a + StableAbi,
impl<'a, T> StableAbi for &'a mut Twhere
T: 'a + StableAbi,
type IsNonZeroType = True
const LAYOUT: &'static TypeLayout = _
source§impl<P> StableAbi for Cell<P>where
P: StableAbi,
impl<P> StableAbi for Cell<P>where
P: StableAbi,
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl<P> StableAbi for UnsafeCell<P>where
P: StableAbi,
impl<P> StableAbi for UnsafeCell<P>where
P: StableAbi,
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl<P> StableAbi for ManuallyDrop<P>where
P: StableAbi,
impl<P> StableAbi for ManuallyDrop<P>where
P: StableAbi,
type IsNonZeroType = <P as StableAbi>::IsNonZeroType
const LAYOUT: &'static TypeLayout = _
source§impl<P> StableAbi for Wrapping<P>where
P: StableAbi,
impl<P> StableAbi for Wrapping<P>where
P: StableAbi,
type IsNonZeroType = <P as StableAbi>::IsNonZeroType
const LAYOUT: &'static TypeLayout = _
source§impl<P> StableAbi for Pin<P>where
P: StableAbi,
impl<P> StableAbi for Pin<P>where
P: StableAbi,
type IsNonZeroType = <P as StableAbi>::IsNonZeroType
const LAYOUT: &'static TypeLayout = _
source§impl<T0> StableAbi for PhantomData<(T0,)>where
T0: StableAbi,
impl<T0> StableAbi for PhantomData<(T0,)>where
T0: StableAbi,
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl<T0, T1> StableAbi for PhantomData<(T0, T1)>
impl<T0, T1> StableAbi for PhantomData<(T0, T1)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
source§impl<T0, T1, T2> StableAbi for PhantomData<(T0, T1, T2)>
impl<T0, T1, T2> StableAbi for PhantomData<(T0, T1, T2)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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)>
type IsNonZeroType = False
const LAYOUT: &'static TypeLayout = _
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.