Skip to main content

weaveffi/abi/
mod.rs

1//! The stable C ABI runtime: the error struct, memory helpers,
2//! reference-counted objects, cancel tokens, callback-interface vtables,
3//! iterators, the value-buffer codec, and the async executor hook.
4//!
5//! Producers rarely name these items. The `#[weaveffi::module]` expansion
6//! and [`export_runtime!`](crate::export_runtime) call into them as
7//! `::weaveffi::abi::*`, so every `unsafe` pointer operation a producer
8//! performs has one audited home. The normative description of the contract
9//! this module implements is `docs/src/reference/abi.md` in the WeaveFFI
10//! repository.
11#![allow(unsafe_code)]
12
13pub mod buffer;
14pub mod callback;
15pub mod cancel;
16pub mod contract;
17pub mod convert;
18pub mod error;
19pub mod iter;
20pub mod leak;
21pub mod marshal;
22pub mod object;
23pub mod spawn;
24
25pub use buffer::{
26    decode_value, encode_value, BufferDecodeError, BufferReader, BufferValue, BufferWriter,
27    ByValue, FixedWidth,
28};
29pub use callback::{
30    callback_ret_buffer, callback_ret_bytes, callback_ret_enum, callback_ret_object,
31    callback_ret_object_opt, callback_ret_string, callback_status, callback_status_in,
32    lift_callback, lift_callback_opt, CallbackInterface, ForeignCallback, ForeignError, Vtable,
33    VtableHeader, VtableTooSmall,
34};
35pub use cancel::{
36    cancel_token_cancel, cancel_token_create, cancel_token_destroy, cancel_token_is_cancelled,
37    AtomicWaker, CancelToken, Cancellable, FfiCancelToken,
38};
39pub use contract::{contract_compact, contract_len, contract_table, ContractEntry};
40pub use convert::{
41    adopt_bytes, alloc, bytes_into_raw, free_bytes, lift_byte_slice, lift_bytes, lift_str,
42    lift_string, lower_bytes, lower_string,
43};
44pub use error::{
45    boxed_error, error_clear, error_free, error_set, error_set_c, error_set_payload_c, error_store,
46    panic_message, ErrorDomain, ErrorReport, FfiError, CANCELLED_ERROR_CODE, FOREIGN_ERROR_CODE,
47    GENERIC_ERROR_CODE, MARSHAL_ERROR_CODE, PANIC_ERROR_CODE,
48};
49pub use iter::{iter_destroy, iter_into_raw, iter_next, Iter, IterHandle};
50pub use leak::debug_live;
51pub use marshal::{
52    buffer_run, byte_slots, bytes_run, call_sync, lift_buffer_param, lift_bytes_param,
53    lift_callback_opt_param, lift_callback_param, lift_enum, lift_object_arc_opt_param,
54    lift_object_arc_param, lift_object_opt_param, lift_object_param, lift_self, lift_self_arc,
55    lift_slice_param, lift_str_param, lift_string_param, lower_buffer_ret, lower_bytes_ret,
56    lower_string_ret, read_enum, str_slots, string_run, write_enum, CEnum, Sentinel,
57};
58pub use object::{
59    lower_object, lower_object_opt, object_arc, object_clone, object_destroy, object_from_token,
60    object_ref, object_to_token,
61};
62pub use spawn::{
63    block_on, default_pool_size, launch_async, run_async, set_spawner, spawn, BoxFuture,
64    CatchUnwind, SpawnError, Spawner, SpawnerAlreadySet,
65};
66
67/// The revision of the WeaveFFI C ABI this runtime implements.
68///
69/// Every producer exports it as `{prefix}_abi_version()` (via
70/// `weaveffi::export_runtime!()`), and every generated consumer compares it
71/// with the revision it was generated against when it loads the library,
72/// turning a silent memory-layout mismatch into a clear error.
73///
74/// The number only changes when the runtime surface (the error layout, the
75/// value-buffer encoding, the object or callback-interface conventions, or
76/// the set and signatures of the runtime symbols) changes incompatibly. It's
77/// independent of the crate version and of the IDL schema version.
78///
79/// Revision 4 replaced the per-module checksums with per-declaration
80/// contract tables, gave callback vtables a size-checked header and every
81/// return family (with `throws` and optional callback parameters), exported
82/// `{prefix}_alloc` on every target (removing `{prefix}_dealloc`), and added
83/// `{prefix}_error_set_payload`.
84pub const ABI_VERSION: u32 = 4;