Macro interoptopus::inventory[][src]

macro_rules! inventory {
    ($export_function : ident, [$($const : path), * $(,) ?],
 [$($function : path), * $(,) ?], [$($extra_type : ty), * $(,) ?],
 [$($pattern : path), * $(,) ?]) => { ... };
}
Expand description

The macro to define your library, ties everything together!

This macro produces an “inventory function”, which can be ingested by backends. The function will have the signature fn f() -> Library, where Library represents all functions, types, constants and documentation exported by this crate over the FFI boundary.

Usage

This macro must be invoked with exactly 5 parameters:

ⓘ
inventory_function!(symbol, consts, functions, extra_types, patterns);

Where

  • symbol - the name of the exported inventory function producing a Library,
  • consts - a list of #[ffi_constant] constants to include [C1, C2, ...],
  • functions - a list of #[ffi_function] functions to include [f1, f2, ...],
  • extra_types - additional types not inferred from functions, e.g., when using void pointers.
  • patterns - a list of LibraryPattern to include [p1, ...],

Any of consts, functions or patters can be an empty list [] instead. Most types are inferred automatically based on the used functions.

Example

use interoptopus::{ffi_function, ffi_constant};

#[ffi_constant]
const MY_CONSTANT: u8 = 1;

#[ffi_function]
#[no_mangle]
pub extern "C" fn f(_x: u8) {}

interoptopus::inventory!(
    my_inventory_function,
    [ MY_CONSTANT ],
    [ f ],
    [], []
);

You can then use my_inventory_function, which will return a Library, in a backend to produce bindings to your language.