Rustler

Documentation | Getting Started | Example

Build Status

Rustler is a library for writing Erlang NIFs in safe Rust code. That means there should be no ways to crash the BEAM (Erlang VM). The library provides facilities for generating the boilerplate for interacting with the BEAM, handles encoding and decoding of Erlang terms, and catches rust panics before they unwind into C.

The library provides functionality for both Erlang and Elixir, however Elixir is favored as of now.

Features:

Getting started

The easiest way of getting started is the rustler elixir library.

NOTE: If you have previously used Rustler, you need to run mix archive.uninstall rustler_installer.ez to remove it before generating the NIF.

How it looks like

This is the code for a minimal NIF that adds two numbers and returns the result. ```rust

![feature(plugin)]

![plugin(rustler_codegen)]

[macro_use]

extern crate rustler; use rustler::{ NifEnv, NifTerm, NifResult, NifEncoder };

rustlerexportnifs!( "Elixir.TestNifModule", [("add", 2, add)], None );

fn add<'a>(env: &'a NifEnv, args: &Vec) -> NifResult> { let num1: i64 = try!(args[0].decode()); let num2: i64 = try!(args[1].decode()); Ok((num1 + num2).encode(env)) } ```

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.