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
Should NifTerm be an enum? #34
Comments
This id certainly an interesting idea. It would be incredibly neat if you where able to use pattern matching on terms. The main problem I can think of is that this would require us to recursively check the type of every term that enters nif-land. Because there is no function that returns the absolute type of a term, we would need to use the |
I may have misunderstood a bit? |
You could always submit a PR to the OTP Erlang project to add such a callback to get the type of a term as an enumeration. But yes, right now you'd need to use |
@hansihe yes this is exactly what I had in mind. I also share the cost concern associated with recursively testing each term. The main thing is that I find that you will need to do this sort of thing in user code anyways. Here is an incomplete example for turning erlang terms to JSON: https://github.com/scrogson/fast_json/blob/master/native/fast_json/src/lib.rs.in#L88-L102 Obviously not the most ergonomic way to deal with this sort of thing. Perhaps it could be apart of the match term.decode(env) {
Atom { ... } => ...,
...
}
@OvermindDL1 can you expand on this? |
@scrogson your use case is something I hadn't considered. I have mainly been using it for cases where you already knew the structure of the type you wanted to ship in and out of erlang-land. An alternative to making all types dynamic would be to have a Edit: Missed your code example. That is pretty much exactly how what I wrote would look like. |
@hansihe sounds good! Let me know when it's ready and I'll give it a shot. |
Closed by #39 |
The erlang compiler is open-source, you could submit a PR to add a function like |
It would be really nice to be able to use
match
on anyNifTerm
.There are
enif_is_*
functions available in theerlang_nif_sys
to determine each of the variants above.@hansihe thoughts?
The text was updated successfully, but these errors were encountered: