Bridgerust: One Rust Core, Every Ecosystem
Source: Dev.to
Introduction
Write high‑performance infrastructure libraries for Python, Node.js, and other ecosystems, powered by a shared Rust core.
BridgeRust lets you write your library once in Rust and automatically generate native, high‑performance bindings for multiple languages.
How BridgeRust Works
BridgeRust is a unified framework that provides:
- Project scaffold – set up a multi‑language project in seconds.
- Unified macro system – a single
#[export]macro works for all target languages. - Type conversions – automatic mapping of
Vec,Option,Result, and more. - Building & publishing – integrated CLI to build wheels and npm packages.
Getting Started
Project initialization
bridge init my-awesome-lib
cd my-awesome-lib
Writing exported functions
// src/lib.rs
use bridgerust::export;
#[export]
pub fn greet(name: String) -> String {
format!("Hello, {}! This is logic from Rust.", name)
}
#[export]
pub struct Point {
pub x: f64,
pub y: f64,
}
#[export]
pub fn fast_math(points: Vec) -> f64 {
// Heavy computation here...
points.iter().map(|p| p.x + p.y).sum()
}
Building packages
bridge build --all
The command generates:
- A Python wheel (
pip install …) - A Node.js native addon (
npm install …)
Example Usage
Python
import my_awesome_lib
print(my_awesome_lib.greet("Pythoneer"))
p1 = my_awesome_lib.Point(1.0, 2.0)
result = my_awesome_lib.fast_math([p1])
Node.js
const lib = require("my-awesome-lib");
console.log(lib.greet("JavaScripter"));
const p1 = new lib.Point(1.0, 2.0);
const result = lib.fastMath([p1]); // fast_math → fastMath automatically
Real‑World Example: Embex
We built Embex, a universal vector‑database client, with BridgeRust. It supports Pinecone, Qdrant, LanceDB, and more, while maintaining a single Rust codebase for core logic (connection pooling, retry strategies, SIMD operations).
- Python package:
pip install embex - Node.js package:
npm install @bridgerust/embex
Key Benefits
- Zero boilerplate – no manual
PyModuleornapi_register_moduledefinitions. - Performance – zero‑cost abstractions keep your code running at native Rust speed.
- Developer experience – the CLI streamlines the entire lifecycle from init to publish.
- Consistency – Python and JavaScript users receive identical features and bug fixes simultaneously.
Getting the CLI and Resources
-
Install the CLI:
cargo install bridge -
Repository:
-
Documentation:
Stop writing glue code. Start building bridges. 🦀🌉