1个不稳定版本
| 0.1.0 | 2022年6月21日 |
|---|
#6 in #bigint
225KB
5K SLoC
Rustler BigInt
rustler_bigint 为Erlang的任意大小整数提供支持。
安装
将以下内容添加到 Cargo.toml
[dependencies]
rustler_bigint = { version = "0.1" }
示例
假设我们需要处理不同大小的整数。一些可能适合Rust的 i64,但其他可能不行。例如
large = Bitwise.bsl(2, 65) # This does not fit into i64, it is an Erlang big integer
在Rust中,我们可以使用 rustler_bigint::BigInt 将不同大小的整数值传递到NIF中。类型 rustler_bigint::BigInt 是一个封装了 num_bigint::BigInt 的新类型,并实现了 std::ops::Deref,因此可以直接调用 num_bigint::BigInt 的函数。
/// Simply echo `large` back to the caller.
#[rustler::nif]
pub fn handle_large(large: rustler_bigint::BigInt) -> NifResult<rustler_bigint::BigInt> {
Ok(large)
}
依赖项
~0.5–0.9MB
~17K SLoC