uniffi-bindgen-react-native
is a tool that generates TypeScript bindings for Rust code, making it usable in React Native apps and web pages. It builds on UniFFI, Mozilla's bindings generator ecosystem.
With this tool, you can write your business logic once in Rust and access it seamlessly from TypeScript, whether you're developing for mobile platforms or the web.
UniFFI provides procedural macros to describe your API, prioritizing expressivity and memory safety. This makes it ideal for portability.
It provides tooling to generate safe and performant TypeScript to access Rust from:
- 📱 React Native
- with JSI C++ to call Rust from TypeScript and back again, and
- a Turbo-Module that installs the bindings into a running React Native library.
- 🌐 Web pages
- with a WASM binding crate
All using the same proc macros: you annotate your Rust once, and build for Android, iOS and the Web.
Javascript hosts the Rust library, and uniffi-bindgen-react-native
and uniffi
facilitate the communication between the two:
- Same thread calling across the FFI from Javascript to Rust.
- Async calls from Javascript to Rust
- Same thread callbacks from Rust to Javascript
- Async callbacks from Rust to Javascript
- Pass by Reference (for "Objects")
- Pass by Value (for "Records")
- Enums and tagged unions
uniffi-bindgen-react-native
generates awasm-bindgen
crate, fromuniffi
annotations.- when you come to use your Rust crate in another context (say, from Python, or Kotlin, or React Native), then you can generate FFIs for those platforms, all with the same
uniffi
annotations.
If you're ready to start, then begin with a step-by-step tutorial to make a Rust turbo-module and then run it in web page with WASM.
If you're new to UniFFI, then the UniFFI user guide or the UniFFI examples are interesting places to start.
- 🧩 Spend more time writing TypeScript and Rust, less time hand-writing FFIs
- 🌍 Your Rust SDK is portable across multiple languages
- @unomed/react-native-matrix-sdk
- ChessTiles on iOS "uniffi-bindgen-react-native lets us run our performance critical solution search algorithm and business logic in Rust, while rapidly prototying the UI with React Native"
Now uniffi-bindgen-react-native
supports WASM, the React Native
no longer seems appropriate. In the near future, we'll change the name to uniffi-bindgen-javascript
. Backwards compatibility will be ensured.
If this tool sounds interesting to you, please help us develop it! You can:
- View the contributor guidelines.
- File or work on issues here in GitHub.
- Join discussions in the #uniffi-bindgen-js:matrix.org room on Matrix.
This project is governed by Mozilla's Community Participation Guidelines.
uniffi-bindgen-react-native
is led by James Hugman, with deep collaboration from the Filament engineering team, funded by Filament and Mozilla.