Rustler helps write Erlang NIFs in Rust so BEAM crashes from NIF code are avoided. It handles encoding, decoding, and panic boundaries for Erlang and Elixir.
Overview
Rustler is a library for implementing Native Implemented Functions on the Erlang VM using safe Rust patterns. It generates interaction boilerplate, converts between Rust values and Erlang terms, and traps Rust panics before they unwind into C so the BEAM should not crash from typical NIF mistakes.
Features include straightforward encode/decode helpers, deriving encodable structs with attributes, and resource objects that pass Rust struct references into Erlang with automatic cleanup when references disappear. Elixir is the preferred onboarding path via the rustler Hex package and mix rustler.new scaffolding.
The project documents a minimum supported Rust version, targets recent OTP and Elixir releases, and selects NIF API versions through Cargo features on the dependency. An optional serde feature aligns with serde-based workflows.
Community support is offered on Matrix and Elixir Slack channels. Licensing is dual Apache-2.0 or MIT.
Key features
- BEAM-safe NIF wrappers
- Erlang term encode and decode
- Derive macros for types
- Resource object lifetimes
- Elixir mix generator
- Configurable NIF API version
- Optional serde integration
- Panic handling before C unwind
Use cases
- Performance-critical Elixir extensions
- Rust libraries exposed to Erlang
- Shared native code in OTP apps
- Safer NIFs than raw C
- Gradual Rust adoption in BEAM stacks