Closed
Description
I'd like to see how far we can go to provide the most ergonomic API for building NIFs.
Given that all NIFs have the same signature:
static ERL_NIF_TERM fun(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
It would be nice to provide a way to define a Rust function that would only be concerned with Rust types:
#[rustler::nif]
fn add(a: i64, b: i64) -> i64 {
a + b
}
rustler::init!("Elixir.Math", [add]);
The arguments (a
and b
in this case) would automatically be decoded from
ERL_NIF_TERM
to an i64
. The return type (i64
) would automatically be
encoded into the appropriate ERL_NIF_TERM
.
Essentially, arguments must implement Decoder
while all return types must implement Encoder
.
I've started working on a PoC a while back (https://github.com/scrogson/rusterlium) and I'd like to see what others think about making this a reality.
Thoughts?
Metadata
Metadata
Assignees
Labels
No labels