Skip to main content

Crate wolfram_export

Crate wolfram_export 

Source
Expand description

Unified runtime for #[export]-marked Wolfram LibraryLink functions.

Pick modes via Cargo features:

wolfram-export = { version = "0.5", features = ["wxf"] }   # typed WXF
wolfram-export = { version = "0.5", features = ["wstp"] }  # WSTP Link
wolfram-export = "0.5"                                     # native + margs (default)

#[export(margs)] (raw MArgument, manual marshaling) rides on the native feature — there’s no separate feature flag for it.

Then in your code (shown here with every mode enabled):

use wolfram_export::{export, sys::MArgument, wstp::Link};

#[export]         fn add(a: f64, b: f64) -> f64 { a + b }
#[export(margs)]  fn raw_add(args: &[MArgument], ret: MArgument) {
    unsafe { *ret.real = *args[0].real + *args[1].real; }
}
#[export(wstp)]  fn echo(link: &mut Link) { let _ = link; }
#[export(wxf)]   fn dot(a: Vec<f64>, b: Vec<f64>) -> f64 {
    a.iter().zip(&b).map(|(x, y)| x * y).sum()
}

Each mode’s wire shape, runtime, and Cargo dep set live in its own feature-gated submodule below. The ExportEntry inventory and the __wolfram_manifest__ C symbol are always on (they’re tiny and how the cargo wl build tool discovers exports).

Modules§

macro_utils
Macro-runtime helpers. Re-exports of the per-mode macro_utils modules behind a single wolfram_export::macro_utils::* namespace so the proc-macro can emit one consistent path regardless of mode.
native
Runtime support for native-mode exports (#[export]), which are called over the raw MArgument C ABI. Runtime support for #[export]-marked native (MArgument-based) LibraryLink functions.
sys
Raw wolfram-library-link-sys C-FFI types (WolframLibraryData, MArgument, mint, …). Available whenever any LibraryLink-using mode is enabled.

Enums§

ExportEntry
Inventory entry for one #[export]-marked function.

Traits§

NativeFunction
Trait implemented for any function whose parameters and return type are native LibraryLink MArgument types.

Functions§

exported_library_functions_association
Returns an Association containing the names and LibraryFunctionLoad calls for every #[export(..)]-marked function in this library.

Attribute Macros§

export
Export a function as a Wolfram LibraryLink function. See export for the four wire-format modes (native, margs, wstp, wxf) and the Cargo features each one needs. Export a function as a Wolfram LibraryLink function, in one of four wire formats picked by a keyword argument. All four need LibraryFunctionLoad on the Wolfram side and none of them need the automate-function-loading-boilerplate feature to work — that feature only affects whether cargo wl build can discover the load call for you (#[export(margs)] needs an args =/ret = annotation for that discovered call to be correct — see below).
init
Designate a one-time library-load initialization function. See init. Designate an initialization function to run once, when this library is loaded via Wolfram LibraryLink — distinct from [export], which wraps a function called on every invocation from Wolfram.