Skip to content

Commit a851069

Browse files
committed
cargo: hide num_bigint v0.3 behind feature flag
Hidden public usages of the `num_bigint::BigInt` (version 0.3) behind `num-bigint-03` feature flag.
1 parent ae623b0 commit a851069

File tree

9 files changed

+39
-31
lines changed

9 files changed

+39
-31
lines changed

examples/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ futures = "0.3.6"
1010
openssl = "0.10.32"
1111
rustyline = "9"
1212
rustyline-derive = "0.6"
13-
scylla = {path = "../scylla", features = ["ssl", "cloud", "chrono", "time"]}
13+
scylla = {path = "../scylla", features = ["ssl", "cloud", "chrono", "time", "num-bigint-03"]}
1414
tokio = {version = "1.1.0", features = ["full"]}
1515
tracing = "0.1.25"
1616
tracing-subscriber = { version = "0.3.14", features = ["env-filter"] }

scylla-cql/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ snap = "1.0"
2020
uuid = "1.0"
2121
thiserror = "1.0"
2222
bigdecimal = "0.2.0"
23-
num-bigint = "0.3"
23+
num-bigint-03 = { package = "num-bigint", version = "0.3", optional = true }
2424
chrono = { version = "0.4.27", default-features = false, optional = true }
2525
lz4_flex = { version = "0.11.1" }
2626
async-trait = "0.1.57"
@@ -40,4 +40,5 @@ harness = false
4040
secret = ["secrecy"]
4141
time = ["dep:time"]
4242
chrono = ["dep:chrono"]
43-
full-serialization = ["chrono", "time", "secret"]
43+
num-bigint-03 = ["dep:num-bigint-03"]
44+
full-serialization = ["chrono", "time", "secret", "num-bigint-03"]

scylla-cql/src/frame/response/cql_to_rust.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::frame::value::{
33
Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, CqlVarint,
44
};
55
use bigdecimal::BigDecimal;
6-
use num_bigint::BigInt;
76
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
87
use std::hash::{BuildHasher, Hash};
98
use std::net::IpAddr;
@@ -150,7 +149,8 @@ impl<const N: usize> FromCqlVal<CqlValue> for [u8; N] {
150149
}
151150
}
152151

153-
impl FromCqlVal<CqlValue> for BigInt {
152+
#[cfg(feature = "num-bigint-03")]
153+
impl FromCqlVal<CqlValue> for num_bigint_03::BigInt {
154154
fn from_cql(cql_val: CqlValue) -> Result<Self, FromCqlValError> {
155155
match cql_val {
156156
CqlValue::Varint(cql_varint) => Ok(cql_varint.into()),
@@ -405,7 +405,6 @@ mod tests {
405405
use crate::frame::value::{Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid};
406406
use crate::macros::FromRow;
407407
use bigdecimal::BigDecimal;
408-
use num_bigint::{BigInt, ToBigInt};
409408
use std::collections::HashSet;
410409
use std::net::{IpAddr, Ipv4Addr};
411410
use std::str::FromStr;
@@ -469,12 +468,15 @@ mod tests {
469468
assert_eq!(Ok(ip_addr), IpAddr::from_cql(CqlValue::Inet(ip_addr)));
470469
}
471470

471+
#[cfg(feature = "num-bigint-03")]
472472
#[test]
473473
fn varint_from_cql() {
474+
use num_bigint_03::ToBigInt;
475+
474476
let big_int = 0.to_bigint().unwrap();
475477
assert_eq!(
476478
Ok(big_int),
477-
BigInt::from_cql(CqlValue::Varint(0.to_bigint().unwrap().into()))
479+
num_bigint_03::BigInt::from_cql(CqlValue::Varint(0.to_bigint().unwrap().into()))
478480
);
479481
}
480482

scylla-cql/src/frame/response/result.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ pub fn deser_cql_value(typ: &ColumnType, buf: &mut &[u8]) -> StdResult<CqlValue,
672672
}
673673
Decimal => {
674674
let scale = types::read_int(buf)? as i64;
675-
let int_value = num_bigint::BigInt::from_signed_bytes_be(buf);
675+
let int_value = bigdecimal::num_bigint::BigInt::from_signed_bytes_be(buf);
676676
let big_decimal: BigDecimal = BigDecimal::from((int_value, scale));
677677

678678
CqlValue::Decimal(big_decimal)
@@ -968,8 +968,6 @@ mod tests {
968968
use crate as scylla;
969969
use crate::frame::value::{Counter, CqlDate, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid};
970970
use bigdecimal::BigDecimal;
971-
use num_bigint::BigInt;
972-
use num_bigint::ToBigInt;
973971
use scylla::frame::response::result::{ColumnType, CqlValue};
974972
use std::str::FromStr;
975973
use uuid::Uuid;
@@ -1029,10 +1027,13 @@ mod tests {
10291027
assert_eq!(double_serialize, CqlValue::Double(double));
10301028
}
10311029

1030+
#[cfg(feature = "num-bigint-03")]
10321031
#[test]
10331032
fn test_varint() {
1033+
use num_bigint_03::ToBigInt;
1034+
10341035
struct Test<'a> {
1035-
value: BigInt,
1036+
value: num_bigint_03::BigInt,
10361037
encoding: &'a [u8],
10371038
}
10381039

scylla-cql/src/frame/value.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::frame::frame_errors::ParseError;
22
use crate::frame::types;
33
use bigdecimal::BigDecimal;
44
use bytes::BufMut;
5-
use num_bigint::BigInt;
65
use std::borrow::Cow;
76
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
87
use std::convert::TryInto;
@@ -306,15 +305,17 @@ impl CqlVarint {
306305
}
307306
}
308307

309-
impl From<BigInt> for CqlVarint {
310-
fn from(value: BigInt) -> Self {
308+
#[cfg(feature = "num-bigint-03")]
309+
impl From<num_bigint_03::BigInt> for CqlVarint {
310+
fn from(value: num_bigint_03::BigInt) -> Self {
311311
Self(value.to_signed_bytes_be())
312312
}
313313
}
314314

315-
impl From<CqlVarint> for BigInt {
315+
#[cfg(feature = "num-bigint-03")]
316+
impl From<CqlVarint> for num_bigint_03::BigInt {
316317
fn from(val: CqlVarint) -> Self {
317-
BigInt::from_signed_bytes_be(&val.0)
318+
num_bigint_03::BigInt::from_signed_bytes_be(&val.0)
318319
}
319320
}
320321

@@ -1007,7 +1008,8 @@ impl Value for CqlVarint {
10071008
}
10081009
}
10091010

1010-
impl Value for BigInt {
1011+
#[cfg(feature = "num-bigint-03")]
1012+
impl Value for num_bigint_03::BigInt {
10111013
fn serialize(&self, buf: &mut Vec<u8>) -> Result<(), ValueTooBig> {
10121014
let serialized = self.to_signed_bytes_be();
10131015
let serialized_len: i32 = serialized.len().try_into().map_err(|_| ValueTooBig)?;

scylla-cql/src/frame/value_tests.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use super::value::{
1212
};
1313
use bigdecimal::BigDecimal;
1414
use bytes::BufMut;
15-
use num_bigint::BigInt;
1615
use std::collections::hash_map::DefaultHasher;
1716
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
1817
use std::hash::{BuildHasherDefault, Hash, Hasher};
@@ -110,13 +109,14 @@ fn cql_varint_normalization() {
110109
}
111110
}
112111

112+
#[cfg(feature = "num-bigint-03")]
113113
#[test]
114-
fn cql_varint_normalization_with_bigint() {
114+
fn cql_varint_normalization_with_bigint03() {
115115
let test_cases = cql_varint_normalization_test_cases();
116116

117117
for test in test_cases {
118-
let non_normalized: BigInt = CqlVarint::from_signed_bytes_be(test.0).into();
119-
let normalized: BigInt = CqlVarint::from_signed_bytes_be(test.1).into();
118+
let non_normalized: num_bigint_03::BigInt = CqlVarint::from_signed_bytes_be(test.0).into();
119+
let normalized: num_bigint_03::BigInt = CqlVarint::from_signed_bytes_be(test.1).into();
120120

121121
assert_eq!(non_normalized, normalized);
122122
}
@@ -147,8 +147,9 @@ fn cql_varint_serialization() {
147147
}
148148
}
149149

150+
#[cfg(feature = "num-bigint-03")]
150151
#[test]
151-
fn bigint_serialization() {
152+
fn bigint03_serialization() {
152153
let cases_from_the_spec: &[(i64, Vec<u8>)] = &[
153154
(0, vec![0x00]),
154155
(1, vec![0x01]),
@@ -161,7 +162,7 @@ fn bigint_serialization() {
161162
];
162163

163164
for (i, b) in cases_from_the_spec {
164-
let x = BigInt::from(*i);
165+
let x = num_bigint_03::BigInt::from(*i);
165166
let b_with_len = (b.len() as i32)
166167
.to_be_bytes()
167168
.iter()
@@ -195,7 +196,7 @@ fn bigdecimal_serialization() {
195196
.chain(serialized_digits)
196197
.cloned()
197198
.collect::<Vec<_>>();
198-
let digits = BigInt::from(*digits);
199+
let digits = bigdecimal::num_bigint::BigInt::from(*digits);
199200
let x = BigDecimal::new(digits, exponent as i64);
200201
assert_eq!(serialized(x, ColumnType::Decimal), repr);
201202
}

scylla-cql/src/types/serialize/value.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::net::IpAddr;
77
use std::sync::Arc;
88

99
use bigdecimal::BigDecimal;
10-
use num_bigint::BigInt;
1110
use thiserror::Error;
1211
use uuid::Uuid;
1312

@@ -242,7 +241,8 @@ impl SerializeCql for CqlVarint {
242241
.map_err(|_| mk_ser_err::<Self>(typ, BuiltinSerializationErrorKind::SizeOverflow))?
243242
});
244243
}
245-
impl SerializeCql for BigInt {
244+
#[cfg(feature = "num-bigint-03")]
245+
impl SerializeCql for num_bigint_03::BigInt {
246246
impl_serialize_via_writer!(|me, typ, writer| {
247247
exact_type_check!(typ, Varint);
248248
// TODO: The allocation here can be avoided and we can reimplement
@@ -1514,8 +1514,8 @@ mod tests {
15141514
};
15151515
use crate::types::serialize::{CellWriter, SerializationError};
15161516

1517+
use bigdecimal::num_bigint::BigInt;
15171518
use bigdecimal::BigDecimal;
1518-
use num_bigint::BigInt;
15191519
use scylla_macros::SerializeCql;
15201520

15211521
use super::{SerializeCql, UdtSerializationErrorKind, UdtTypeCheckErrorKind};

scylla/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ cloud = ["ssl", "scylla-cql/serde", "dep:serde_yaml", "dep:serde", "dep:url", "d
2020
secret = ["scylla-cql/secret"]
2121
chrono = ["scylla-cql/chrono"]
2222
time = ["scylla-cql/time"]
23-
full-serialization = ["chrono", "time", "secret"]
23+
num-bigint-03 = ["scylla-cql/num-bigint-03"]
24+
full-serialization = ["chrono", "time", "secret", "num-bigint-03"]
2425

2526
[dependencies]
2627
scylla-macros = { version = "0.3.0", path = "../scylla-macros" }
@@ -37,7 +38,6 @@ rand = "0.8.3"
3738
thiserror = "1.0"
3839
itertools = "0.11.0"
3940
bigdecimal = "0.2.0"
40-
num-bigint = "0.3"
4141
tracing = "0.1.36"
4242
chrono = { version = "0.4.20", default-features = false, features = ["clock"] }
4343
openssl = { version = "0.10.32", optional = true }
@@ -57,6 +57,7 @@ rand_pcg = "0.3.1"
5757
socket2 = { version = "0.5.3", features = ["all"] }
5858

5959
[dev-dependencies]
60+
num-bigint-03 = { package = "num-bigint", version = "0.3" }
6061
scylla-proxy = { version = "0.0.3", path = "../scylla-proxy" }
6162
ntest = "0.9.0"
6263
criterion = "0.4" # Note: v0.5 needs at least rust 1.70.0

scylla/src/transport/cql_types_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::transport::session::Session;
99
use crate::utils::test_utils::unique_keyspace_name;
1010
use bigdecimal::BigDecimal;
1111
use itertools::Itertools;
12-
use num_bigint::BigInt;
1312
use scylla_cql::frame::value::{CqlTimeuuid, CqlVarint};
1413
use scylla_cql::types::serialize::value::SerializeCql;
1514
use scylla_macros::SerializeCql;
@@ -104,6 +103,7 @@ where
104103
}
105104
}
106105

106+
#[cfg(feature = "num-bigint-03")]
107107
#[tokio::test]
108108
async fn test_varint() {
109109
let tests = [
@@ -119,7 +119,7 @@ async fn test_varint() {
119119
"-123456789012345678901234567890",
120120
];
121121

122-
run_tests::<BigInt>(&tests, "varint").await;
122+
run_tests::<num_bigint_03::BigInt>(&tests, "varint").await;
123123
}
124124

125125
#[tokio::test]

0 commit comments

Comments
 (0)