explaingit

rusterlium/rustler

4,789RustAudience · developerComplexity · 3/5LicenseSetup · moderate

TLDR

A Rust library for writing safe native extensions (NIFs) that run inside the Erlang/Elixir VM, with crash protection and automatic type conversion between Rust and Erlang types.

Mindmap

mindmap
  root((repo))
    What it does
      Safe Rust NIFs
      VM crash prevention
      Automatic type conversion
    Features
      Panic interception
      Boilerplate generation
      Serde integration
      Resource objects
    Use Cases
      High-performance Elixir code
      Safe native extensions
      Shared Rust objects
    Tech Stack
      Rust
      Elixir
      Erlang OTP
    Getting Started
      Mix dependency
      Generator command
      Minimal example
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Write a CPU-intensive function in Rust and call it from your Elixir app without risking a VM crash

USE CASE 2

Add a high-performance Rust NIF to an existing Elixir project in under an hour using the mix rustler.new generator

USE CASE 3

Pass complex Rust structs into Elixir with automatic type conversion using a single annotation on the struct

USE CASE 4

Integrate Serde serialization to share data between Rust and Elixir without manual data conversion code

Tech stack

RustElixirErlangOTP

Getting it running

Difficulty · moderate Time to first run · 30min

Requires both a Rust toolchain and Elixir/OTP installed on the same machine.

Use freely for any purpose, commercial or personal, under either MIT or Apache 2.0 terms, whichever suits your project.

In plain English

Rustler is a library that lets developers write performance-critical code in Rust and call it from Erlang or Elixir programs. In Erlang's runtime, these are called NIFs, short for Native Implemented Functions. Writing NIFs directly in C is the traditional approach, but C code that crashes or behaves incorrectly can bring down the entire Erlang virtual machine with it. Rustler's main goal is to prevent that: code written through this library should not be able to crash the virtual machine, even if it encounters an unexpected error condition. The library handles the tedious parts of NIF development automatically. It generates the required boilerplate code, converts data between Erlang's internal format and Rust types, and intercepts Rust panics before they can propagate into C territory. Converting a Rust struct to something Erlang can understand takes a single annotation on the struct definition. Passing a reference to a Rust object into Erlang is also supported, with automatic cleanup when Erlang's garbage collector no longer holds a reference to it. Getting started in an Elixir project involves adding the Rustler package as a dependency and running a generator command that creates a skeleton NIF. The README shows a minimal example: a two-argument addition function in Rust becomes callable from Elixir with a few lines of code. Serde integration is available as an optional feature for projects that already use Rust's popular serialization library. Rustler supports the three most recent major OTP releases and the three most recent minor Elixir releases. It is dual-licensed under the MIT and Apache 2.0 licenses.

Copy-paste prompts

Prompt 1
Generate a Rustler NIF in Rust for an Elixir project that computes Fibonacci numbers and returns the result as an integer
Prompt 2
How do I convert a Rust HashMap to an Elixir map using Rustler encode and decode traits?
Prompt 3
Set up a new Elixir project with a Rustler NIF using mix new and the rustler generator command, step by step
Prompt 4
Handle a Rust panic safely inside a Rustler NIF so it returns an Elixir error tuple instead of crashing the BEAM VM
Prompt 5
Use Rustler with Serde to pass a struct with nested fields between Rust and Elixir without writing manual term conversion
Open on GitHub → Explain another repo

← rusterlium on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.