Expand description
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
pub use lazy_static;
pub use crate::types::Atom;
pub use crate::types::Binary;
pub use crate::types::Decoder;
pub use crate::types::Encoder;
pub use crate::types::OwnedBinary;
pub use crate::resource::ResourceArc;
pub use crate::schedule::SchedulerFlags;
pub use crate::env::Env;
pub use crate::env::OwnedEnv;
pub use crate::thread::spawn;
pub use crate::thread::JobSpawner;
pub use crate::thread::ThreadSpawner;
pub use crate::error::Error;
pub use crate::return::Return;
Modules
Macros
Macro for defining Rust functions that return Erlang atoms.
To use this macro, you must also import the lazy_static
crate.
Implementation of a Native Implemented Function (NIF) macro that lets the user annotate a function that will be wrapped in higer-level NIF implementation.
Exports a given list of functions to a Erlang module.
Structs
Enables iteration over the items in the list.
Term is used to represent all erlang terms. Terms are always lifetime limited by a Env.
Enums
Traits
Type Definitions
Attribute Macros
Implementation of a Native Implemented Function (NIF) macro that lets the user annotate a function that will be wrapped in higer-level NIF implementation.
Derive Macros
Implementation of the NifException
macro that lets the user annotate a struct that will
be translated directly from an Elixir exception to a Rust struct. For example, the following
struct, annotated as such:
Implementation of a macro that lets the user annotate a struct with NifMap
so that the
struct can be encoded or decoded from an Elixir map. For example, the following struct
annotated as such:
Implementation of the NifRecord
macro that lets the user annotate a struct that will
be translated directly from an Elixir struct to a Rust struct. For example, the following
struct, annotated as such:
Implementation of the NifStruct
macro that lets the user annotate a struct that will
be translated directly from an Elixir struct to a Rust struct. For example, the following
struct, annotated as such:
Implementation of a macro that lets the user annotate a struct with NifTuple
so that the
struct can be encoded or decoded from an Elixir tuple. For example, the following struct
annotated as such:
Implementation of the NifUnitEnum
macro that lets the user annotate an enum with a unit type
that will generate elixir atoms when encoded
Implementation of the NifUntaggedEnum
macro that lets the user annotate an enum that will
generate elixir values when decoded. This can be used for rust enums that contain data and
will generate a value based on the kind of data encoded. For example from the test code: