pub unsafe trait Nicheless: Sized { }
Expand description
Indicates that a value of this type is FFI-safe and well-defined no matter the underlying bit-pattern.
Equally, that the type has no niches.
If you are familiar with bytemuck
, types that can implement this trait
are a strict superset of types that can implement bytemuck::Pod
and a strict subset of types that can implement bytemuck::Zeroable
.
Namely, Nicheless
types:
- must be FFI-safe (
#[repr(C)]
,#[repr(Int)]
, or#[repr(transparent)]
over an FFI-safe type). - must be valid for any bit-pattern, not just all zeros.
- are allowed to have padding bytes.
- are allowed to contain pointers, atomics and interior-mutable types.
In the case of niche optimization (where sizeof::<T>() == sizeof::<Option<T>>
),
the type Option<T>
will implement Nicheless
if the trait OneNiche
is implemented for T
.
Iffi
is implemented automatically for all types that implement Nicheless
,
both reflexively and over MaybeInvalid<Self>
.
Safety
- All fields must be nicheless.
- The type must not be uninhabited.
- The type must not have pointer metadata.
- The type must be FFI-safe.