mirror of
https://gitlab.com/artofrev/smallint.git
synced 2024-12-04 09:01:39 -05:00
feature bigint
This commit is contained in:
parent
a5620cdda9
commit
bd10994f4e
|
@ -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" }
|
||||
|
|
11
src/lib.rs
11
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<SmallInt> for u128 {
|
|||
}
|
||||
|
||||
|
||||
#[cfg(feature="num-bigint")]
|
||||
impl From<BigInt> for SmallInt {
|
||||
fn from(b: BigInt) -> Self {
|
||||
match (&b).try_into() {
|
||||
|
@ -149,9 +154,8 @@ impl From<BigInt> for SmallInt {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature="num-bigint")]
|
||||
impl From<SmallInt> for BigInt {
|
||||
|
||||
|
||||
fn from(s: SmallInt) -> Self {
|
||||
match s {
|
||||
SmallInt::Inline(i) => Self::from(i),
|
||||
|
@ -176,6 +180,8 @@ impl From<SmallInt> 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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user