All Projects → rusterlium → Rustler

rusterlium / Rustler

Licence: other
Safe Rust bridge for creating Erlang NIF functions

Programming Languages

rust
11053 projects
elixir
2628 projects
shell
77523 projects

Projects that are alternatives of or similar to Rustler

Emacs Module Rs
Rust binding and tools for emacs-module (Emacs's dynamic module support)
Stars: ✭ 203 (-93.35%)
Mutual labels:  ffi, binding
Pyo3
Rust bindings for the Python interpreter
Stars: ✭ 5,110 (+67.43%)
Mutual labels:  ffi, binding
Node Postal
NodeJS bindings to libpostal for fast international address parsing/normalization
Stars: ✭ 165 (-94.59%)
Mutual labels:  binding
Pythonnet
Python for .NET is a package that gives Python programmers nearly seamless integration with the .NET Common Language Runtime (CLR) and provides a powerful application scripting tool for .NET developers.
Stars: ✭ 2,873 (-5.87%)
Mutual labels:  ffi
Inline Java
Haskell/Java interop via inline Java code in Haskell modules.
Stars: ✭ 197 (-93.55%)
Mutual labels:  ffi
Gtk Fortran
A GTK / Fortran binding
Stars: ✭ 171 (-94.4%)
Mutual labels:  binding
Rust Ffi Guide
A guide for doing FFI using Rust
Stars: ✭ 207 (-93.22%)
Mutual labels:  ffi
Rustr
Rust and R Integration
Stars: ✭ 160 (-94.76%)
Mutual labels:  ffi
Kaguya
C++ binding to Lua
Stars: ✭ 247 (-91.91%)
Mutual labels:  binding
Cairocffi
CFFI-based cairo bindings for Python.
Stars: ✭ 186 (-93.91%)
Mutual labels:  binding
Awesome Php Ffi
PHP FFI examples and use cases
Stars: ✭ 217 (-92.89%)
Mutual labels:  ffi
Raylib Cs
C# bindings for raylib, a simple and easy-to-use library to learn videogames programming
Stars: ✭ 182 (-94.04%)
Mutual labels:  binding
Goluwa
a game framework written in luajit
Stars: ✭ 173 (-94.33%)
Mutual labels:  ffi
Inline Rust
Use snippets of Rust inline in your Haskell programs
Stars: ✭ 210 (-93.12%)
Mutual labels:  ffi
Node Tree Sitter
Node.js bindings for tree-sitter
Stars: ✭ 172 (-94.36%)
Mutual labels:  binding
Rxdatasources
UITableView and UICollectionView Data Sources for RxSwift (sections, animated updates, editing ...)
Stars: ✭ 2,784 (-8.78%)
Mutual labels:  binding
Mgs Machinery
Unity plugin for binding machinery joint in scene.
Stars: ✭ 164 (-94.63%)
Mutual labels:  binding
Rust Bindgen
Automatically generates Rust FFI bindings to C (and some C++) libraries.
Stars: ✭ 2,453 (-19.63%)
Mutual labels:  ffi
Python Mpv
Python interface to the awesome mpv media player
Stars: ✭ 245 (-91.97%)
Mutual labels:  ffi
Nimterop
Nimterop is a Nim package that aims to make C/C++ interop seamless
Stars: ✭ 244 (-92.01%)
Mutual labels:  binding

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:

  • Safety - The code you write in a Rust NIF should never be able to crash the BEAM.
  • Interop - Decoding and encoding rust values into Erlang terms is as easy as a function call.
  • Type composition - Making a Rust struct encodable and decodable to Erlang or Elixir can be done with a single attribute.
  • Resource objects - Enables you to safely pass a reference to a Rust struct into Erlang code. The struct will be automatically dropped when it's no longer referenced.

Getting started

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

  • Add the rustler elixir library as a dependency of your project.
  • Run mix rustler.new to generate a new NIF in your project. Follow the instructions.
  • If you're already using serde, consider using serde_rustler to easily encode and decode your data types into and from Elixir terms.

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

What it looks like

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

#[rustler::nif]
fn add(a: i64, b: i64) -> i64 {
    a + b
}

rustler::init!("Elixir.Math", [add]);

Supported OTP and Elixir Versions

Rustler aims to support the newest three OTP versions as well as Elixir versions capable of running the supported versions of OTP.

Supported NIF version

Rustler uses erlang:system_info(nif_version) to detect the supported NIF version of the Erlang/OTP system for which the NIF is to be compiled. It is possible to restrict the NIF version to an older version if the NIF is to be compiled for an older version of Erlang. For example, if the target NIF version should be 2.14 (Erlang/OTP 21), this can be defined using an environment variable:

RUSTLER_NIF_VERSION=2.14 mix compile

Community

You can find us in #rustler on freenode or the elixir-lang slack.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].