Trait abi_stable::abi_stability::stable_abi_trait::StableAbi[][src]

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.

Associated Types

Whether this type has a single invalid bit-pattern.

Possible values:True/False

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.

An alternative 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*

Associated Constants

The layout of the type provided by implementors.

const-equivalents of the associated types.

Implementations on Foreign Types

When the “const_params” feature is disabled, this trait is implemented for arrays of up to 32 elements.

Implementing abi stability for Option is fine if T is a NonZero primitive type.

Implementors