rustler/
lib.rs

1#![allow(non_camel_case_types)]
2#![allow(clippy::missing_safety_doc)]
3
4//! [Github](https://github.com/rusterlium/rustler)
5//! [Example](https://github.com/rusterlium/NifIo)
6//!
7//! Rustler is a library for writing Erlang NIFs in safe Rust code. That means there should be no
8//! ways to crash the BEAM (Erlang VM). The library provides facilities for generating the
9//! boilerplate for interacting with the BEAM, handles encoding and decoding of Erlang terms, and
10//! catches rust panics before they unwind into C.
11//!
12//! The library provides functionality for both Erlang and Elixir, however Elixir is favored as of
13//! now.
14//!
15//! This crate provides the entire runtime library for rustler. Code generators are located in the
16//! rustler_codegen library.
17//!
18//! # Getting Started
19//! There is a [`:rustler`](https://hex.pm/packages/rustler) package on hex.pm that provides
20//! functionality which makes working with Rustler easier, including project generators, an
21//! automatic NIF compiler for Mix, and utilities for loading the compiled NIF.
22//!
23//! For more information about this, see [the documentation for
24//! rustler](https://hexdocs.pm/rustler).
25
26#[doc(hidden)]
27pub mod wrapper;
28
29#[doc(hidden)]
30pub mod codegen_runtime;
31
32mod alloc;
33pub use crate::alloc::EnifAllocator;
34
35#[macro_use]
36pub mod types;
37
38mod term;
39
40pub use crate::term::Term;
41pub use crate::types::{
42    Atom, Binary, Decoder, Encoder, ErlOption, ListIterator, LocalPid, MapIterator, NewBinary,
43    OwnedBinary, Reference,
44};
45
46#[cfg(feature = "big_integer")]
47pub use crate::types::BigInt;
48
49mod resource;
50pub use crate::resource::{Monitor, Resource, ResourceArc, ResourceInitError};
51
52#[doc(hidden)]
53pub mod dynamic;
54pub use crate::dynamic::TermType;
55
56pub mod schedule;
57pub use crate::schedule::SchedulerFlags;
58pub mod env;
59pub use crate::env::{Env, OwnedEnv};
60pub mod thread;
61pub use crate::thread::{spawn, JobSpawner, ThreadSpawner};
62
63pub mod error;
64pub use crate::error::Error;
65
66pub mod r#return;
67pub use crate::r#return::Return;
68
69#[doc(hidden)]
70mod nif;
71pub use nif::Nif;
72
73pub type NifResult<T> = Result<T, Error>;
74
75pub use rustler_codegen::{
76    init, nif, resource_impl, NifException, NifMap, NifRecord, NifStruct, NifTaggedEnum, NifTuple,
77    NifUnitEnum, NifUntaggedEnum,
78};
79
80#[cfg(feature = "serde")]
81pub mod serde;
82
83#[cfg(feature = "serde")]
84pub use crate::serde::SerdeTerm;
85
86pub mod sys;