Skip to content

Core Concepts

BridgeRust automatically converts between Rust types and their target language equivalents.

Rust TypePython TypeNode.js TypeNotes
StringstrstringCopied on conversion
i32, f64, etc.int, floatnumber
boolboolboolean
Vec<T>List[T]T[]Converted recursively
Option<T>Optional[T]T | nullNone becomes None/null
Result<T, E>T (or raise)T (or throw)Err causes an exception
struct (exported)classclassMust be marked with #[export]

BridgeRust has first-class support for async functions.

#[bridgerust::export]
pub async fn fetch_data(url: String) -> Result<String> {
// Standard Rust async code
let resp = reqwest::get(url).await?.text().await?;
Ok(resp)
}
  • Python: Returns an Awaitable (coroutine). Use await fetch_data(...) in Python.
  • Node.js: Returns a Promise. Use await fetch_data(...) in JavaScript.

runtime requirement: For async functions to work, you generally need a runtime. BridgeRust assumes a Tokio runtime is available if you use async features.

Return Result<T, E> from your functions. If E implements ToString or Display, it will be converted into:

  • Python: RuntimeError (or a custom exception if configured).
  • Node.js: Error object (rejected Promise for async).
#[bridgerust::export]
pub fn divide(a: f64, b: f64) -> Result<f64, String> {
if b == 0.0 {
return Err("Cannot divide by zero".to_string());
}
Ok(a / b)
}