Expand description
Stable ABI building blocks for Rust dynamic module systems.
xabi provides a small C-compatible ABI surface for hosts and dynamically
loaded modules. The high-level path is:
- define an ABI trait with
xabi, - aggregate exported implementations with
module, - load the dynamic module with
loadorModule::load, - use the generated
XabiV1HandleTrait*handle on the host side.
§Define a trait ABI
pub const TRAIT_ID: &str = "xabi.example.Demo";
pub const ABI_VERSION: u32 = 1;
#[xabi::data]
#[derive(Clone, Copy)]
pub struct BuildInput {
pub value: u64,
}
#[xabi::xabi(id = TRAIT_ID, version = ABI_VERSION)]
pub trait Demo {
fn name(&self) -> String;
async fn build(&self, input: BuildInput) -> xabi::Result<Vec<u8>>;
async fn load(&self, details: &[u8]) -> xabi::Result<()>;
}§Export an implementation
#[derive(Default)]
struct DemoImpl;
#[xabi::module]
mod exports {
use super::*;
#[xabi::xabi(name = "demo", version = 1)]
impl Demo for DemoImpl {
fn name(&self) -> String {
"demo".to_string()
}
async fn build(&self, input: BuildInput) -> xabi::Result<Vec<u8>> {
Ok(input.value.to_le_bytes().to_vec())
}
async fn load(&self, _details: &[u8]) -> xabi::Result<()> {
Ok(())
}
}
}Structs§
- Module
- Loaded xabi module with a validated manifest.
- Module
Handle - Reference-counted handle for a loaded xabi module.
- SendPtr
- Sendable wrapper for raw pointers that are only dereferenced on a known-safe thread.
- Xabi
Bytes - Borrowed byte slice passed across the ABI boundary.
- Xabi
Contract Layout - Layout metadata for a generated xabi contract.
- Xabi
Error Wire - Wire representation for
Errorwhen it is used as ancrate::XabiType. - Xabi
Export - Export descriptor in an xabi module manifest.
- Xabi
Field Layout - Layout metadata for a C-compatible field.
- Xabi
Future - Future handle returned by async xabi vtable methods.
- Xabi
Future Handle - Rust
Futurewrapper around a foreignXabiFuture. - Xabi
Layout - A generated xabi contract layout.
- Xabi
Manifest - Static manifest exported by an xabi module.
- Xabi
Option - Optional xabi payload.
- Xabi
Owned Bytes - Raw owned-byte descriptor passed across the ABI boundary.
- Xabi
Owned Bytes Owner - Safe RAII owner for a producer-owned byte payload.
- Xabi
Result - Status plus optional owned payload returned by the future poll ABI.
- Xabi
Slice - Borrowed typed slice passed across the ABI boundary.
- XabiStr
- Borrowed UTF-8 string passed across the ABI boundary.
- Xabi
Type Layout - Layout metadata for a C-compatible type.
- Xabi
Typed Future - Rust
Futurewrapper that decodes typed values and export errors. - XabiV
Table Layout - Prefix metadata for a generated vtable.
- Xabi
Waker - Waker handle passed into the xabi future poll ABI.
Enums§
- Error
- Error type used by xabi runtime helpers.
- Xabi
Call Error - Error returned by generated host-side xabi handles.
- Xabi
Layout Item - One item in a xabi layout snapshot.
- Xabi
Layout Stability - Stability rules for a type layout.
Constants§
- ABI_
VERSION - Version of xabi’s core runtime structures.
- CAP_
NONE - Empty capability bitset for xabi descriptors.
- ERR_
EXPORT - The export reported an error.
- ERR_
HOST - A host callback reported an error.
- ERR_
INVALID_ ARGUMENT - The caller provided an invalid argument.
- ERR_
PANIC - The callee caught a panic before it crossed the ABI boundary.
- OK
- Successful FFI status code.
- POLL_
PENDING - A future is still pending.
- POLL_
READY - A future completed and wrote an
crate::XabiResult.
Traits§
- Xabi
Contract - Trait implemented by ABI descriptors generated by
crate::xabi. - Xabi
Layout Collector - Collector used by generated layout descriptors.
- Xabi
Layout Source - A generated source of xabi layout entries.
- Xabi
Type - Rust type that has a stable xabi representation.
Functions§
- catch_
unwind_ code - Convert a panic-catching FFI closure into a status code.
- catch_
unwind_ or - Convert a panic-catching closure into a caller-provided default value.
- catch_
unwind_ owned - Convert a panic-catching FFI closure into an owned byte payload.
- load⚠
- Load an xabi module from a native library path.
- status_
to_ result - Convert a raw xabi status code into a
Result. - validate_
abi_ version - Validate that an ABI structure uses the expected version.
- validate_
exact_ size - Validate that an ABI structure has exactly the expected size.
- validate_
size - Validate that an ABI structure is at least as large as the required prefix.
Type Aliases§
- Result
- Result type used by xabi runtime helpers.