Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

miniffi

> 编程语言
Open source

miniffi [!WARNING] This project is on its first release. I'm still trying out the idea. It has not been used in production. This is a simpl…

380 stars0 likes0 views
WebsiteGitHub

About

miniffi [!WARNING] This project is on its first release. I'm still trying out the idea. It has not been used in production. This is a simpl…

miniffi

[!WARNING] This project is on its first release. I'm still trying out the idea. It has not been used in production.

This is a simple but opinionated FFI system for Rust. It allows you to call Rust code from other languages, and vice versa. Some design principles:

  • Intended for writing platform-agnostic Rust with platform-specific details in the host language
  • FFI support is split into data (structs passed by copy) and code (traits passed by reference)
  • Rather than have a separate schema language, the public API in your lib.rs is your schema
  • The generated binding code is compact, dependency-free, and straightforward to integrate with

Supported Features

  • Primitive types (bool, i32, f64, String, etc.)
  • Tuples
  • Structs
  • Enums
  • Top-level constants
  • Top-level functions
  • Traits (must be either Box or Rc)
  • Vec
  • Option
  • Box

Available Targets

  • JavaScript/TypeScript (WASM)
  • Swift
  • C++

Example

After setting everything up, using miniffi looks something like this. The following example Rust code (in lib.rs) demonstrates passing code and data back and forth between Rust and the host language:

rust
pub enum Level {
    Warning,
    Error,
}

pub trait Logger {
    fn log(&self, level: Level, text: &str);
}

pub trait Demo {
    fn run(&self, logger: Box);
}

pub fn get_demo() -> Box {
    struct DemoImpl;
    impl Demo for DemoImpl {
        fn run(&self, logger: Box) {
            logger.log(Level::Warning, "example");
        }
    }
    Box::new(DemoImpl)
}

// This includes the binding code generated by miniffi
include!(concat!(env!("OUT_DIR"), "/miniffi.rs"));

Unlike other FFI systems, there are no annotations required to expose something from lib.rs to the host language other than using pub to mark things public. The miniffi build script parses lib.rs, extracts the supported parts of the public API, and generates FFI binding code both for Rust (the miniffi.rs file referenced above) and for the host language. Calling that example Rust code might look like this:

In JavaScript/TypeScript:

javascript
import * as rust from "./miniffi.js"
import fs from "fs"

await rust.instantiate(fs.readFileSync(
    "./target/wasm32-unknown-unknown/debug/example.wasm"))

rust.get_demo().run({
    log(level, text) {
        if (level === rust.Level.Error)
            console.error("ERROR:", text)
        else if (level === rust.Level.Warning)
            console.warn("WARNING:", text)
    }
})

In Swift:

swift
class LoggerImpl : Logger {
    func log(_ level: Level, _ text: String) {
        if level == .Error {
            print("ERROR:", text)
        } else if level == .Warning {
            print("WARNING:", text)
        }
    }
}

get_demo().run(LoggerImpl())

In C++:

cpp
#include 
#include "ffi.h"

struct LoggerImpl : rust::Logger {
    void log(rust::Level level, std::string text) {
        if (level == rust::Level::Error)
            std::cout run(std::make_unique());
    return 0;
}

More information about how to use miniffi can be found in the documentation.

Similar Projects

These projects are much further along, and you may want to use them instead:

  • UniFFI
  • Diplomat
  • Interoptopus

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言