4 releases (2 breaking)
0.3.0 | May 27, 2022 |
---|---|
0.2.0 | May 27, 2022 |
0.1.1 | May 26, 2022 |
0.1.0 | May 26, 2022 |
#7 in #nif
20KB
239 lines
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:- calling back into Elixir might indeed take quite some time.
- we want to prevent schedulers to wait for themselves, which might otherwise sometimes happen.
Dependencies
~330–660KB
~13K SLoC