Bridgerust:一个 Rust 核心,遍及所有生态系统

发布: (2026年1月8日 GMT+8 22:10)
3 min read
原文: Dev.to

Source: Dev.to

Introduction

为 Python、Node.js 以及其他生态系统编写高性能基础设施库,核心由共享的 Rust 实现。
BridgeRust 让你只需用 Rust 编写一次库,即可自动生成面向多语言的本地高性能绑定。

How BridgeRust Works

BridgeRust 是一个统一的框架,提供:

  • 项目脚手架 – 在几秒钟内搭建多语言项目。
  • 统一宏系统 – 单一的 #[export] 宏可用于所有目标语言。
  • 类型转换 – 自动映射 VecOptionResult 等。
  • 构建与发布 – 集成的 CLI 可构建 wheel 包和 npm 包。

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

该命令会生成:

  • 一个 Python wheel(pip install …
  • 一个 Node.js 原生插件(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

我们使用 BridgeRust 构建了 Embex,一个通用向量数据库客户端。它支持 Pinecone、Qdrant、LanceDB 等,同时保持核心逻辑(连接池、重试策略、SIMD 操作)仅有一套 Rust 代码。

  • Python 包:pip install embex
  • Node.js 包:npm install @bridgerust/embex

Key Benefits

  • 零样板代码 – 无需手动编写 PyModulenapi_register_module 定义。
  • 性能 – 零成本抽象让你的代码以原生 Rust 速度运行。
  • 开发者体验 – CLI 简化了从初始化到发布的完整生命周期。
  • 一致性 – Python 与 JavaScript 用户同时获得相同的功能和 bug 修复。

Getting the CLI and Resources

  • 安装 CLI:

    cargo install bridge
  • 仓库:

  • 文档:


停止编写胶水代码,开始搭建桥梁。 🦀🌉

Back to Blog

相关文章

阅读更多 »

Copilot SDK 技术预览

Copilot SDK 现已进入技术预览,提供针对特定语言的 SDK,以编程方式访问 GitHub Copilot CLI。可用的 SDK 包括…