Macro interoptopus::pattern_api_guard[][src]

macro_rules! pattern_api_guard {
    ($name : ident, $inventory : ident) => { ... };
}
Expand description

Defines a helper function ensuring the bindings match the used DLL.

The generated function can be called manually and will return a u64 hash value. In addition, backends might issue an automatic version check when loading the DLL by comparing the version the DLL reports with the version stored in the interop bindings.

Hash Value

The hash value

  • is based on the signatures of the involved functions, types and constants,
  • is expected to change when the API changes, e.g., functions, types, fields, … are added changed or removed,
  • will even react to benign API changes (e.g., just adding functions),
  • might even react to documentation changes (subject to change; feedback welcome).

Example

This will create a FFI function called check_abi, and backends might automatically create guards calling this function when loading the DLL.

use interoptopus::{inventory, pattern_api_guard, Library};

/// Define an inventory function `my_inventory`.
interoptopus::inventory!(
    my_inventory, [],
    // Also register `check_abi` below.
    [ check_api ],
    [], []
);

// Define a guard function called `check_api` and make it use inventory.
// Note: This looks circular, but isn't.
pattern_api_guard!(check_api, my_inventory);