A safe Rust library for creating Erlang NIFs that prevents crashes in the BEAM VM.
Rustler is a library for writing Erlang Native Implemented Functions (NIFs) in Rust. It provides a safe bridge between Rust and the Erlang VM, ensuring that Rust code cannot crash the BEAM while offering seamless interoperability. The library supports both Erlang and Elixir, with a current focus on Elixir integration.
Erlang and Elixir developers who need to write high-performance, safe native extensions in Rust. It is particularly suited for Elixir projects that require integrating Rust code for computationally intensive tasks.
Developers choose Rustler because it guarantees safety by preventing Rust panics from crashing the Erlang VM, and it simplifies interoperability with easy encoding/decoding of values and automatic resource management. Its focus on developer experience and safety makes it the preferred choice over writing unsafe C NIFs.
Safe Rust bridge for creating Erlang NIF functions
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Rustler catches Rust panics before they unwind into C, ensuring the Erlang VM never crashes due to NIF errors, as explicitly stated in the README.
Encoding and decoding between Rust and Erlang terms is simplified to function calls, making data passing straightforward and reducing boilerplate.
Using a single attribute like #[derive(Rustler::NifTuple)] makes Rust structs easily encodable and decodable, streamlining type composition as highlighted in the features.
Resource objects allow safe passing of Rust struct references to Erlang, with automatic cleanup when no longer referenced, preventing memory leaks without manual management.
The README admits Elixir is favored, which may result in poorer documentation, tooling, and community support for developers working solely with Erlang.
Users must manually enable Cargo features for specific NIF versions (e.g., nif_version_2_16), adding setup complexity and potential for compatibility issues.
Effectively using Rustler requires proficiency in both Rust and Erlang/Elixir, increasing the learning curve and development time for teams unfamiliar with one ecosystem.
The safety mechanisms, while preventing crashes, may introduce minor performance overhead compared to less safe, hand-rolled C NIFs, which could matter in latency-sensitive applications.