Crate rustler

source ·
Expand description

Github Example

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.

This crate provides the entire runtime library for rustler. Code generators are located in the rustler_codegen library.

§Getting Started

There is a :rustler package on hex.pm that provides functionality which makes working with Rustler easier, including project generators, an automatic NIF compiler for Mix, and utilities for loading the compiled NIF.

For more information about this, see the documentation for rustler.

Re-exports§

Modules§

Macros§

  • Macro for defining Rust functions that return Erlang atoms. To use this macro, you must also import the lazy_static crate.
  • Initialise the Native Implemented Function (NIF) environment and register NIF functions in an Elixir module.
  • rustler_atomsDeprecated
  • Exports a given list of functions to a Erlang module.

Structs§

  • Term is used to represent all erlang terms. Terms are always lifetime limited by a Env.

Enums§

Traits§

Type Aliases§

Attribute Macros§

  • Wrap a function in a Native Implemented Function (NIF) implementation, so that it can be called from Elixir, with all encoding and decoding steps done automatically.

Derive Macros§

  • Derives implementations for the Encoder and Decoder traits which convert between an Elixir exception and a Rust struct.
  • Derives implementations for the Encoder and Decoder traits which convert between Rust struct and an Elixir map.
  • Derives implementations for the Encoder and Decoder traits which convert between a Rust struct and an Elixir record.
  • Derives implementations for the Encoder and Decoder traits which convert between an Elixir struct and a Rust struct.
  • Implementation of the NifTaggedEnum macro that lets the user annotate an enum that will generate elixir values when encoded. This can be used for any rust enums and will generate three types of values based on the kind of the enum. For example from the test code:
  • Derives implementations for the Encoder and Decoder traits which convert between a Rust struct and an Elixir tuple.
  • Derives implementations for the Encoder and Decoder traits which convert between an enum and a union of elixir atoms.
  • Derives implementations for the Encoder and Decoder traits which convert between a Rust enum and a union of Elixir types.