rusterlium / rustler

Safe Rust bridge for creating Erlang NIF functions
https://docs.rs/crate/rustler
Apache License 2.0
4.24k stars 222 forks source link

[Feature request] Add support for i128 and u128 #594

Closed Munksgaard closed 4 months ago

Munksgaard commented 4 months ago

Since both Rust and Elixir have support for 128-bit sized integers (i128, u128, erlang) it seems natural that Rustler should support it as well.

I have a specific use case for i128s as well, which is implementing support for the Decimal type from Polars in Explorer.

Munksgaard commented 4 months ago

I can't really figure out if this is going to be a problem, but at least it's something to be aware of.

evnu commented 4 months ago

Would this work for you: https://github.com/rusterlium/rustler/tree/master/rustler_bigint ?

filmor commented 4 months ago

I can't really figure out if this is going to be a problem, but at least it's something to be aware of.

I don't think this is relevant for Rustler. It would be, if the NIF API actually included (C-based) support for 128-bit integer types, but it only supports up to 64.

If someone wants to work on this, https://github.com/rusterlium/rustler/tree/master/rustler_bigint can be taken as a basis. While that library is more general and implements support for arbitrarily-sized integers, the same approach (going via the term_to_binary) can be used for the standard library types i128 and u128.

Munksgaard commented 4 months ago

I have not had time to look at the bigint library yet, but it indeed seems like the easiest way to handle something like this.

filmor commented 4 months ago

Implemented in #600.

Munksgaard commented 4 months ago

Incredible! Thank you for your work @filmor!