GithubHelp home page GithubHelp logo

baitcenter / rustler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rusterlium/rustler

0.0 1.0 0.0 972 KB

Safe Rust bridge for creating Erlang NIF functions

Home Page: https://docs.rs/crate/rustler

License: Apache License 2.0

Rust 61.53% Elixir 12.59% Erlang 8.74% HTML 0.06% Shell 1.41% C 0.14% Vim Snippet 15.52%

rustler's Introduction

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 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.7 (Erlang/OTP 17.3), this can be defined using an environment variable:

RUSTLER_NIF_VERSION=2.7 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.

rustler's People

Contributors

alex-shapiro avatar costaraphael avatar cristianberneanu avatar cybernetlab avatar davydog187 avatar dependabot-preview[bot] avatar dovahcrow avatar erik-nymi avatar evnu avatar filmor avatar getong avatar goertzenator avatar hansihe avatar jdemaris avatar jeremyjh avatar jorendorff avatar josevalim avatar kylemayes avatar masonforest avatar mfeckie avatar mischov avatar nlfiedler avatar nobbz avatar padde avatar royalicing avatar scrogson avatar sdwolfz avatar slashmili avatar tatsuya6502 avatar yjh0502 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.