Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Safe Rust bridge for creating Erlang NIF functions

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
Unknown
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

rusterlium/rustler

Repository files navigation

Documentation |Getting Started |Example

GitHub Actions Workflow StatusHex.pm package versionCrates.io package versionLast Updated

Rustler is a library for writing Erlang NIFs in safe Rust code. That meansthere should be no ways to crash the BEAM (Erlang VM). The library providesfacilities for generating the boilerplate for interacting with the BEAM,handles encoding and decoding of Erlang terms, and catches rust panics beforethey unwind into C.

The library provides functionality for both Erlang and Elixir, however Elixiris 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 therustler Elixir library.

  • Add therustler Elixir library as adependency of your project.
  • Runmix rustler.new to generate a new NIF in your project. Follow theinstructions.
  • If you are already usingserde and/or have been usingserde_rustler before, please enable theserde feature in your NIF crate'sCargo.toml on therustler dependency.

What it looks like

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

#[rustler::nif]fnadd(a:i64,b:i64) ->i64{    a + b}rustler::init!("Elixir.Math");

Minimal Supported Rust Version (MSRV)

Rustler currently has a minimal supported Rust version (MSRV) of 1.70. Thisis the configured version in.clippy.toml.

Supported OTP and Elixir Versions

Rustler aims to support the newest three major OTP versions as well as newest three minor Elixir versions.

Supported NIF version

The minimal supported NIF version for a library should be defined via Cargofeatures. The default is currently2.15 (Erlang/OTP 22). To use features fromNIF version2.16 (Erlang/OTP 24) or2.17 (Erlang/OTP 26), the respectivefeature flag has to be enabled on the dependency:

[dependencies]rustler = {version ="...",features = ["nif_version_2_16"] }

Community

You can find us in the#rustler:matrix.org channel onMatrixor in the#rustler channel inthe Elixir lang Slack.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in the work by you, as defined in the Apache-2.0 license, shall bedual licensed as above, without any additional terms or conditions.

About

Safe Rust bridge for creating Erlang NIF functions

Topics

Resources

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
Unknown
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp