For Rust-to-Rust ffi,with a focus on creating libraries loaded at program startup.
This library allows defining Rust libraries that can be loaded at runtime, even if they were built with a different Rust version than the crate that depends on it,
Currently this library has these features:
ffi-safe equivalent of trait objects for any combination of a selection of traits.
Provides ffi-safe alternatives to standard library types..
StableAbitrait for asserting that types are ffi-safe.
Checking at load-time that the types in the dynamic library have the expected layout, allowing for semver compatible changes while checking the layout of types.
StableAbiderive macro to both assert that the type is ffi compatible, and to get the layout of the type at runtime to check that it is still compatible.
For examples of using
abi_stable you can look at the abi_stable_example_* crates,
in the repository for this crate.
interface crate:the crate that declares the public functions and types that
are necessary to load the library at runtime.
ìmplementation crate:A crate that implements all the functions in the interface crate.
user crate:A crate that depends on an
interface crate and
loads 1 or more
ìmplementation crates for it.
module:refers to a struct of function pointers and other static values,
and implement the ModuleTrait trait.
These are declared in the
interface crate,exported in the
and loaded in the
Types must implement StableAbi to be safely passed through the FFI boundary, which can be done using the StableAbi derive macro.
These are the 2 kinds of types passed through FFI:
Value kind: The layout of types passed by value must not change in a minor version. This is the default kind when deriving StableAbi.
Opaque kind: Types wrapped in
VirtualWrapper<SomePointer<OpaqueType<Interface>>>, whose layout can change in any version of the library, and can only be unwrapped back to the original type in the dynamic library/binary that created it.
Adding variants or fields to a variant is disallowed in minor versions.
To represent non-exhaustive enums without fields it is recommended using structs and associated constants so that it is not UB to keep adding field-less variants in minor versions.
types and traits related to abi stability.
Types and traits related to type erasure.
Wrapper type(s) where their value is ignored in some trait impls .
A late-initialized static reference.
Traits and types related to loading an abi_stable dynamic library, as well as functions/modules within.
Zero-sized types .
Traits for pointers.
Miscelaneous items re-exported from core_extensions.
Contains many ffi-safe equivalents of standard library types. The vast majority of them can be converted to and from std equivalents.
Where miscellaneous traits reside.
Types representing the version number of a library.
Use this to make sure that you handle panics inside
Implements the abi_stable::type_info::GetTypeInfo trait for some type.
Use this when constructing a
A handle to any dynamically loaded library, not necessarily ones that export abi_stable compatible modules.
A Zero-sized type used by
VirtualWrapper implements ffi-safe trait objects,for a selection of traits.
Defines the usable/required traits when creating a
Represents a type whose layout is stable.
Used by vtables/pointers to signal that the type has been erased.