rustler_elixir_fun

Crates.iorustler_elixir_fun
lib.rsrustler_elixir_fun
version0.3.0
sourcesrc
created_at2022-05-26 14:52:47.10364
updated_at2022-05-27 12:17:48.633676
descriptionCall Elixir functions from NIFs implemented in Rust.
homepage
repositoryhttps://github.com/Qqwy/elixir-rustler_elixir_fun
max_upload_size
id594157
size10,661
Qqwy / Marten (Qqwy)

documentation

README

rustler_elixir_fun

Ever wanted to call an Elixir function from inside some Rust code? Now you can!

This crate exposes the Rust code to interact with from your Rust code side.

See the main GitHub repo for more details.

Installation

  • Add it as a dependency to your Cargo.toml.
  • Add the Elixir library of the same name to your mix.exs.

Usage

The main function to call is apply_elixir_fun:

let some_result : Result<Term, Error> = rustler_elixir_fun::apply_elixir_fun(env, pid_or_process_name, fun, parameters)

This function will attempt to call fun using parameters on the Elixir side, and block the caller until a result is available.

  • Be sure to register any NIF that calls this function as a 'Dirty CPU NIF'! (by annotating your NIFs with #[rustler::nif(schedule = "DirtyCpu")]). This is important for two reasons:
    1. calling back into Elixir might indeed take quite some time.
    2. we want to prevent schedulers to wait for themselves, which might otherwise sometimes happen.
Commit count: 44

cargo fmt