Skip to main content

Crate weaveffi_macros

Crate weaveffi_macros 

Source
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

  • module marks an exported namespace (the driver attribute).
  • export exports a function; record a by-value struct; enumeration a #[repr(i32)] C-style enum.
  • interface declares an opaque object type whose impl block’s pub fns become constructors, methods, and statics.
  • error declares the module’s error domain from a unit-variant enum with explicit discriminants.
  • callback / listener declare a callback and an event listener; cancellable marks 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 ErrorReport implementation.
export
Export a function across the FFI boundary. An async fn lowers to an asynchronous symbol; a fn -> Result<T, E> is fallible.
interface
Declare an interface: an opaque object type with constructors, methods, and statics read from its impl block. Methods must take &self.
listener
Declare an event listener; takes event = "CallbackName".
module
Mark an inline mod as an exported WeaveFFI namespace.
record
Declare a by-value record (struct) with generated create/getters.