This crate provides bindings to the erl_nif C API, making it easy to write native extensions for Erlang and Elixir in Rust.
Write your NIF in Rust:
```rust erl_nif::init!( name: "Elixir.Add", funcs: [add], );
fn add(a: u64, b: u64) -> Result
Then load it in Elixir.
```elixir defmodule Add do @onload {:init, 0} def init do path = :filename.join(:code.privdir(:add), "libadd") :ok = :erlang.load_nif(path, nil) end
def add() do :erlang.niferror(:nifnotloaded) end end ```
See the examples folder for a complete example.
To make it easy to move data structures between Rust and Elixir, the erl_nif crate supports integration with serde.
```rust
struct Contact { name: String, email: String, } ```
elixir
defmodule Example do
defmodule Contact do
defstruct [
:name,
:email
]
end
end