Expand description
Procedural macros that turn safe, annotated Rust into the WeaveFFI C ABI.
A producer annotates an ordinary Rust module with #[weaveffi::module] and
tags the items it wants to export. The macro lowers the module to the
WeaveFFI IR (through weaveffi_bridge), builds the canonical
BindingModel, and emits the
#[no_mangle] extern "C" thunks every generated language binding calls.
All of the unsafe marshalling lives in the weaveffi-abi runtime, so the
producer writes only safe Rust.
ⓘ
#[weaveffi::module]
pub mod calculator {
/// Add two integers.
#[weaveffi::export]
pub fn add(a: i32, b: i32) -> i32 {
a + b
}
}
weaveffi::export_runtime!();The same IR the macro lowers is what weaveffi generate path/to/lib.rs
reads, so the generated bindings and the producer cannot drift.
§Attributes
modulemarks an exported namespace (the driver attribute).exportexports a function;recorda by-value struct;enumerationa#[repr(i32)]C-style enum.interfacedeclares an opaque object type whoseimplblock’spub fns become constructors, methods, and statics.errordeclares the module’s error domain from a unit-variant enum with explicit discriminants.callback/listenerdeclare a callback and an event listener;cancellablemarks an async function as cancellable.
The item-level attributes are inert markers that module reads; on
their own they expand to the item unchanged.
Attribute Macros§
- builder
- Opt a record into a generated fluent builder.
- callback
- Declare a callback function signature the host implements.
- cancellable
- Mark an async function as accepting a cancellation token.
- enumeration
- Declare a C-style
#[repr(i32)]enum exported by value. - error
- Declare the module’s error domain from a unit-variant enum with
explicit discriminants. The module macro generates the matching
ErrorReportimplementation. - export
- Export a function across the FFI boundary. An
async fnlowers to an asynchronous symbol; afn -> Result<T, E>is fallible. - interface
- Declare an interface: an opaque object type with constructors, methods,
and statics read from its
implblock. Methods must take&self. - listener
- Declare an event listener; takes
event = "CallbackName". - module
- Mark an inline
modas an exported WeaveFFI namespace. - record
- Declare a by-value record (struct) with generated create/getters.