-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: attribute to generate pre-encoded NIF functions #254
Comments
I like this format very much. Do you already have a plan how to handle extra options for exported nifs, such as |
I think it would still make sense to at least optionally allow |
It would also be nice if this made listing the nifs optional in |
Yes. It would be handled in the attribute: #[rustler::nif(name = "add2", schedule = "DirtyCpu"]
fn add(a: i64, b: i64) -> i64 {
a + b
}
I definitely agree that
Yeah, it would be, but I don't think there is a way around that. We need a way to map the function pointer to the wrapped implementation. This seems similar to how Rocket's routing works as well. |
I'm starting work on this. I hope to have a PR ready soon-ish. |
Really like this!
We get that basically for free, since both |
@sunny-g Do you see a good way of adjusting your PR (#232) to this?
Depends on how much "parameter interpretation" you want to implement in Erlang/Elixir.
Apart from changing how |
@filmor Not immediately, as it'll likely depend on how this gets implemented. At first glance, it might help if the |
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:
It would be nice to provide a way to define a Rust function that would only be concerned with Rust types:
The arguments (
a
andb
in this case) would automatically be decoded fromERL_NIF_TERM
to ani64
. The return type (i64
) would automatically beencoded into the appropriate
ERL_NIF_TERM
.Essentially, arguments must implement
Decoder
while all return types must implementEncoder
.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?
The text was updated successfully, but these errors were encountered: