- 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::Errorfor 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. ImplementDropfor 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
BinaryandOwnedBinarytypes. - Anti-patterns: no panics in NIFs (crashes the BEAM VM), no blocking the scheduler, no I/O in NIFs.
Rustler Bindings
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.
Rustler Bindings by goldziher · f32be47
npx skillmds@latest add goldziher/rustler-bindings File contents
---name: rustler-bindingsdescription: 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.---- 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.
goldziher/ai-rulez/tree/main/internal/builtins/bindings/rustler/skills/rustler-bindings commit f32be47aa2
Frequently asked questions
Run npx skillmds@latest add goldziher/rustler-bindings in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
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. It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
goldziher (@goldziher) published this skill. Their other Agent Skills are listed on their SkillMD profile.