From bd10994f4e9307b2700a958997da5901e69e7122 Mon Sep 17 00:00:00 2001 From: EvilMuffinHa Date: Tue, 2 Aug 2022 09:21:00 -0400 Subject: [PATCH] feature bigint --- Cargo.toml | 6 +++++- src/lib.rs | 11 +++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3e9ca22..448662e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,4 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -num-bigint = "0.4.3" +num-bigint = { version = "0.4.3", optional = true } + + +[dev-dependencies] +num-bigint = { version = "0.4.3" } diff --git a/src/lib.rs b/src/lib.rs index 60762a2..32650ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,12 @@ //! inline an integer and store it on the stack if that integer is small. However, for larger values, //! this will be instead stored on the heap as a pointer to a `u32` slice, a length, and a sign. +#[cfg(feature="num-bigint")] use num_bigint::BigInt; + +#[cfg(feature="num-bigint")] use num_bigint::Sign; + use core::mem::ManuallyDrop; /// An error that occurred when processing a SmallInt. @@ -132,6 +136,7 @@ impl TryFrom for u128 { } +#[cfg(feature="num-bigint")] impl From for SmallInt { fn from(b: BigInt) -> Self { match (&b).try_into() { @@ -149,9 +154,8 @@ impl From for SmallInt { } } +#[cfg(feature="num-bigint")] impl From for BigInt { - - fn from(s: SmallInt) -> Self { match s { SmallInt::Inline(i) => Self::from(i), @@ -176,6 +180,8 @@ impl From for BigInt { mod conversion_tests { use crate::SmallInt; + + #[cfg(feature="num-bigint")] use num_bigint::{BigInt, Sign}; macro_rules! conversion_tests { @@ -206,6 +212,7 @@ mod conversion_tests { conversion_tests!(i128, test_i128); #[test] + #[cfg(feature="num-bigint")] fn test_bigint() { let i = BigInt::new(Sign::Plus, vec![5, 4, 8, 3, 2, 9, 3]); let s = SmallInt::from(i);