Rustler writes Erlang and Elixir NIFs in safe Rust
Safe Rust bridge for creating Erlang NIF functions
At a glance
- What is it?
- Rustler is a library for writing Erlang NIFs in safe Rust, keeping the BEAM from crashing, handling term encoding, and catching panics before they reach C.
- Who is it for?
- Rustler is a library that lets developers write Erlang and Elixir NIFs in safe Rust, with the explicit aim of never crashing the BEAM. It generates the boilerplate for talking to the VM, encodes and decodes Erlang terms, and catches Rust panics before they cross into C, while supporting both Erlang and Elixir with Elixir as the favored path.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 2 days ago.
- What is it written in?
- Mainly Rust, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 1, 2026, and from our analysis. They are not legal advice.
Editorial analysis
Rustler brings safe Rust to the BEAM
Rustler is a library for writing Erlang NIFs in safe Rust code. A NIF is a native function that runs inside the Erlang virtual machine, the BEAM. The project's goal is that there should be no way to crash the BEAM from the Rust side. To achieve this, Rustler generates the boilerplate needed to talk to the BEAM, handles encoding and decoding of Erlang terms, and catches Rust panics before they unwind into C. The library works with both Erlang and Elixir, though Elixir is favored as of now. This design lets developers keep the speed of native code while protecting the scheduler from the kind of fault that would otherwise take the whole VM down.
#[rustler::nif]
fn add(a: i64, b: i64) -> i64 {
a + b
}
rustler::init!("Elixir.Math");Safety, interop, and type composition features
The README highlights four features. Safety means the code you write in a Rust NIF should never crash the BEAM. Interop makes encoding and decoding Rust values into Erlang terms as easy as a function call. Type composition lets a Rust struct become encodable and decodable to Erlang or Elixir with a single attribute. Resource objects let you safely pass a reference to a Rust struct into Erlang code; the struct is dropped automatically once nothing references it. Together these features let native code call into the VM without the usual risk of taking the scheduler down, and they remove much of the manual marshalling that a hand written NIF would otherwise require. By hiding that marshalling, Rustler shortens the distance between a Rust idea and a callable BEAM function.
Getting started with the Elixir library
The easiest path is the Rustler Elixir library, published on Hex. You add it as a dependency of your project and run `mix rustler.new` to generate a new NIF, then follow the printed instructions. If you already use serde, you enable the serde feature on the rustler dependency in your NIF crate's Cargo.toml. The README notes that Elixir is the primary target, which is why the guide centers on the Mix workflow rather than a raw Erlang setup. That choice keeps the first run close to the normal Elixir build cycle instead of introducing a separate toolchain.
A minimal NIF that adds two numbers
The README shows the smallest useful NIF: a function annotated with `#[rustler::nif]` that takes two i64 values and returns their sum, followed by a `rustler::init!` call that registers the module as `Elixir.Math`. This pattern is the entry point for every Rustler module. Because the init macro names the module, the BEAM can load the compiled NIF and route calls to the Rust functions. The example keeps focus on the interop boundary instead of application logic, which makes it a clear starting template for a first project. The attribute and the init macro together replace the verbose C boilerplate that a classic NIF would need. New users can copy this template and extend the function set without learning the low level NIF C interface.
Supported Rust, OTP, and NIF versions
Rustler currently sets a minimal supported Rust version, the MSRV, at 1.91, configured in `.clippy.toml`. It aims to support the newest three major OTP versions and the newest three minor Elixir versions. The minimal supported NIF version is set through Cargo features, defaulting to 2.15 which maps to Erlang/OTP 22. To use features from NIF version 2.16, tied to Erlang/OTP 24, or 2.17, tied to Erlang/OTP 26, the relevant feature flag must be enabled on the dependency.
[dependencies]
rustler = { version = "...", features = ["nif_version_2_16"] }Community and licensing
The project keeps two chat channels: `#rustler:matrix.org` on Matrix and `#rustler` in the Elixir lang Slack. Rustler is dual licensed under the Apache License, Version 2.0 and the MIT license, at the user's option. Contributions are accepted under the same dual license without extra terms. This permissive licensing makes it straightforward to adopt Rustler in both open source and commercial Elixir or Erlang projects, and it lets teams pick the license that fits their own distribution rules. The active chat rooms also give newcomers a place to ask about NIF design before writing code.
Editorial conclusion
Rustler is a library that lets developers write Erlang and Elixir NIFs in safe Rust, with the explicit aim of never crashing the BEAM. It generates the boilerplate for talking to the VM, encodes and decodes Erlang terms, and catches Rust panics before they cross into C, while supporting both Erlang and Elixir with Elixir as the favored path. The feature set covers safety, easy interop, single attribute type composition, and resource objects that clean up automatically. With an MSRV of 1.91, a rolling window of supported OTP and Elixir versions, and a Cargo feature based NIF version selection, it fits modern toolchains. Dual Apache and MIT licensing and active Matrix and Slack channels make it a practical choice for native extensions in the BEAM ecosystem.
Frequently asked questions
What is a NIF in the Erlang or Elixir context?
A NIF is a native implemented function that runs inside the BEAM, the Erlang virtual machine. The README describes Rustler as a library for writing these NIFs in safe Rust, generating the boilerplate to interact with the BEAM and encoding Erlang terms.
Why does Rustler focus on not crashing the BEAM?
The README states the goal is that there should be no way to crash the BEAM from the Rust side, and that Rustler catches Rust panics before they unwind into C. Its safety feature says a Rust NIF should never be able to crash the BEAM.
Which languages does Rustler support, Elixir or Erlang?
The README says Rustler provides functionality for both Erlang and Elixir, but that Elixir is favored as of now. The getting started guide therefore centers on the Elixir library and the Mix workflow.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/rusterlium-rustler)