Write Erlang and Elixir NIFs in safe Rust
open sourceMIT OR Apache-2.0free
Rustler is a library for writing native implemented functions (NIFs) for the Erlang VM in safe Rust, so native code can't crash the BEAM: it generates the boilerplate for talking to the VM, encodes and decodes Erlang terms, and catches Rust panics before they unwind into C. A single attribute makes a Rust struct encodable to Elixir or Erlang terms, and resource objects pass Rust structs to BEAM code and drop them when they're no longer referenced. It works with Erlang and Elixir, favouring Elixir, whose rustler package on Hex adds a Mix compiler and mix rustler.new. It's dual-licensed under MIT or Apache 2.0.
Problems it solves
- speed up a hot path in my Elixir app by writing it in Rust
- call a Rust library from Elixir without risking a VM crash
- write an Erlang NIF without hand-writing C
Features
- write Erlang VM NIFs in safe Rust
- encodes and decodes Erlang terms
- catches Rust panics before they reach the VM
- derive attribute makes Rust structs encodable
- resource objects for passing Rust structs to BEAM code
- Mix compiler and mix rustler.new generator for Elixir
Alternatives
The same job
These do what Rustler does.
- PyO3 Rust bindings for Python: write Python extensions in Rust or embed Python
- Rustler Precompiled Ships precompiled Rustler NIFs so Elixir users don't need the Rust toolchain
- Unifex Generates the interface between native C code and Elixir
- flutter_rust_bridge Call Rust code from Flutter and Dart, with the glue code generated for you
- bindgen Generates Rust FFI bindings to C and some C++ libraries from their headers
