rustler-bindings

Solid

Rustler conventions for building Elixir NIFs from a Rust core: nif macros, tagged {:ok,_}/{:error,_} tuples, dirty schedulers, ResourceArc state, NifStruct derives, and mix compile. Load when generating or reviewing Rustler Elixir NIF bindings for a Rust library.

Code & Development 137 stars 13 forks Updated today MIT

Install

View on GitHub

Quality Score: 84/100

Stars 20%
71
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
47
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

- Use `#[rustler::nif]` for Elixir NIF functions. Use `#[module = "Elixir.ModuleName"]` for module naming. - Return tagged tuples: `{:ok, value}` / `{:error, reason}`. Use Rustler encoders/decoders for type mapping. - Use `rustler::Error` for NIF error handling. Map Rust errors to descriptive Elixir error tuples. - Keep NIF functions fast (<1ms) to avoid scheduler issues. Use `#[rustler::nif(schedule = "DirtyCpu")]` for long operations. - Build with `mix compile` (Rustler compiler). Test from Elixir using ExUnit. - Use `ResourceArc<T>` for sharing Rust state across NIF calls. Implement `Drop` for cleanup. - Use `#[derive(NifStruct)]` and `#[derive(NifUnitEnum)]` for Elixir-compatible types. - Keep Elixir NIF wrapper thin — business logic in Rust, Elixir provides functional API. - Handle binary data with `Binary` and `OwnedBinary` types. - Anti-patterns: no panics in NIFs (crashes the BEAM VM), no blocking the scheduler, no I/O in NIFs.

Details

Author
Goldziher
Repository
Goldziher/ai-rulez
Created
1 years ago
Last Updated
today
Language
Go
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category