#bignum #big-integer #numeric

infallible_tobigint

Infallible ToBigInt/ToBigUint conversion traits for num-bigint

1 unstable release

0.1.0 Nov 20, 2024

#1173 in Math

Download history 150/week @ 2024-11-18

150 downloads per month

MIT/Apache

17KB
329 lines

Infallible ToBigInt

Crates.io Docs.rs CI

Overview

This crate provides to traits InfallibleToBigInt and InfallibleToBigUint. They provide the to_bigint(&self) and to_biguint(&self) from the popular num-bigint crate. But they are only implemented on types that support infallible conversion, and so they do not return a Result but only BigInt/BigUint. This results in cleaner code.

Installation

Cargo

  • Install the rust toolchain in order to have cargo installed by following this guide.
  • run cargo install infallible_tobigint

Usage

use crate::infallible_to_big_int::*;

// use the conversion directly
153830.to_bigint();

// or define a function which takes any InfallibleToBigInt
fn do_great_things(to_bigint: impl InfallibleToBigInt) {
    let bigint = to_bigint.to_bigint();
    // ... do something nice with bigint here
}

// then you can call it like this
do_great_things(153830)

License

Licensed under either of

at your option.

Dependencies

~465KB