Crate superffi

Crate superffi 

Source
Expand description

§SuperFFI - Multi-Language FFI Binding Generator

SuperFFI is a powerful procedural macro that automatically generates FFI bindings for multiple target languages from your Rust code. Write your Rust code once, and get Python, Node.js, and WebAssembly bindings automatically.

§Features

  • Python bindings via PyO3 (feature: python) - preserves snake_case
  • Node.js bindings via NAPI (feature: nodejs) - automatic camelCase conversion
  • WebAssembly bindings via wasm-bindgen (feature: wasm) - automatic camelCase conversion
  • Automatic naming conventions for consistent JavaScript APIs
  • Zero-cost abstractions - only generates code for enabled features
  • Simple annotation - just add #[superffi] to your items

§Quick Start

Add to your Cargo.toml:

[dependencies]
superffi = { version = "0.1", features = ["python", "nodejs", "wasm"] }

Then annotate your Rust code:

use superffi::superffi;

#[superffi]
pub struct Config {
    pub name: String,
    pub version: u32,
}

#[superffi]
impl Config {
    pub fn new(name: String, version: u32) -> Self {
        Self { name, version }
    }
     
    pub fn get_info(&self) -> String {
        format!("{} v{}", self.name, self.version)
    }
}

#[superffi]
pub fn create_default_config() -> Config {
    Config::new("MyApp".to_string(), 1)
}

§Supported Items

SuperFFI can be applied to:

  • Structs - Generates language-specific class/object bindings
  • Impl blocks - Generates method bindings for the target languages
  • Functions - Generates standalone function bindings

§Automatic Naming Conventions

SuperFFI automatically converts function names to match target language conventions:

Rust FunctionPythonNode.jsWebAssembly
get_info()get_info()getInfo()getInfo()
set_debug()set_debug()setDebug()setDebug()
with_file()with_file()withFile()withFile()

This ensures APIs feel natural in each target language while maintaining consistency.

§Feature Flags

Enable only the target languages you need:

  • python - Generates PyO3 bindings for Python
  • nodejs - Generates NAPI bindings for Node.js
  • wasm - Generates wasm-bindgen bindings for WebAssembly
  • all - Enables all target languages

§Safety and Limitations

  • All generated bindings follow the safety requirements of their respective FFI frameworks
  • Complex generic types may not be supported across all target languages
  • Async functions are not currently supported
  • Some Rust-specific features (like advanced lifetime annotations) may not translate directly

Attribute Macros§

superffi
A procedural macro that generates FFI bindings for multiple target languages.