Skip to content

Commit aeef692

Browse files
authored
RUST-960 Remove the decimal128 feature flag (#287)
1 parent d8c12f7 commit aeef692

21 files changed

+31
-492
lines changed

.evergreen/config.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,6 @@ functions:
9292
${PREPARE_SHELL}
9393
.evergreen/run-tests-u2i.sh
9494
95-
"run decimal128 tests":
96-
- command: shell.exec
97-
type: test
98-
params:
99-
shell: bash
100-
working_dir: "src"
101-
script: |
102-
${PREPARE_SHELL}
103-
.evergreen/run-tests-decimal128.sh
104-
10595
"compile only":
10696
- command: shell.exec
10797
type: test
@@ -160,10 +150,6 @@ tasks:
160150
commands:
161151
- func: "run u2i tests"
162152

163-
- name: "test-decimal128"
164-
commands:
165-
- func: "run decimal128 tests"
166-
167153
- name: "compile-only"
168154
commands:
169155
- func: "compile only"
@@ -197,7 +183,6 @@ buildvariants:
197183
tasks:
198184
- name: "test"
199185
- name: "test-u2i"
200-
- name: "test-decimal128"
201186

202187
- matrix_name: "compile only"
203188
matrix_spec:

.evergreen/run-tests-decimal128.sh

Lines changed: 0 additions & 9 deletions
This file was deleted.

.evergreen/run-tests-serde.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.

Cargo.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ chrono-0_4 = []
3939
uuid-0_8 = []
4040
# attempt to encode unsigned types in signed types
4141
u2i = []
42-
# Decimal128 in BSON 1.1
43-
decimal128 = ["decimal"]
4442

4543
[lib]
4644
name = "bson"
@@ -53,7 +51,6 @@ serde = { version = "1.0", features = ["derive"] }
5351
serde_json = { version = "1.0", features = ["preserve_order"] }
5452
indexmap = "1.6.2"
5553
hex = "0.4.2"
56-
decimal = { version = "2.1.0", default_features = false, optional = true }
5754
base64 = "0.13.0"
5855
lazy_static = "1.4.0"
5956
uuid = "0.8.1"
@@ -64,6 +61,3 @@ assert_matches = "1.2"
6461
serde_bytes = "0.11"
6562
pretty_assertions = "0.6.1"
6663
chrono = { version = "0.4", features = ["serde"] }
67-
68-
[package.metadata.docs.rs]
69-
features = ["decimal128"]

serde-tests/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ edition = "2018"
66

77
[features]
88
u2i = ["bson/u2i"]
9-
decimal128 = ["bson/decimal128"]
109

1110
[dependencies]
1211
bson = { path = ".." }

serde-tests/test.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ use std::{
1414
collections::{BTreeMap, HashSet},
1515
};
1616

17-
#[cfg(feature = "decimal128")]
18-
use bson::Decimal128;
1917
use bson::{
2018
doc,
2119
oid::ObjectId,
@@ -749,16 +747,12 @@ fn all_types() {
749747
let oid = ObjectId::new();
750748
let subdoc = doc! { "k": true, "b": { "hello": "world" } };
751749

752-
#[cfg(not(feature = "decimal128"))]
753750
let decimal = {
754751
let bytes = hex::decode("18000000136400D0070000000000000000000000003A3000").unwrap();
755752
let d = Document::from_reader(bytes.as_slice()).unwrap();
756753
d.get("d").unwrap().clone()
757754
};
758755

759-
#[cfg(feature = "decimal128")]
760-
let decimal = Bson::Decimal128(Decimal128::from_str("2.000"));
761-
762756
let doc = doc! {
763757
"x": 1,
764758
"y": 2_i64,

src/bson.rs

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,7 @@ impl From<Bson> for Value {
361361
impl Bson {
362362
/// Converts the Bson value into its [relaxed extended JSON representation](https://docs.mongodb.com/manual/reference/mongodb-extended-json/).
363363
///
364-
/// Note: extended json encoding for `Decimal128` values is not supported without the
365-
/// "decimal128" feature flag. If this method is called on a case which contains a
366-
/// `Decimal128` value, it will panic.
364+
/// Note: If this method is called on a case which contains a `Decimal128` value, it will panic.
367365
pub fn into_relaxed_extjson(self) -> Value {
368366
match self {
369367
Bson::Double(v) if v.is_nan() => {
@@ -433,13 +431,7 @@ impl Bson {
433431
"$date": { "$numberLong": v.timestamp_millis().to_string() },
434432
}),
435433
Bson::Symbol(v) => json!({ "$symbol": v }),
436-
#[cfg(feature = "decimal128")]
437-
Bson::Decimal128(ref v) => json!({ "$numberDecimal": v.to_string() }),
438-
#[cfg(not(feature = "decimal128"))]
439-
Bson::Decimal128(_) => panic!(
440-
"Decimal128 extended JSON not implemented yet. Use the decimal128 feature to \
441-
enable experimental support for it."
442-
),
434+
Bson::Decimal128(_) => panic!("Decimal128 extended JSON not implemented yet."),
443435
Bson::Undefined => json!({ "$undefined": true }),
444436
Bson::MinKey => json!({ "$minKey": 1 }),
445437
Bson::MaxKey => json!({ "$maxKey": 1 }),
@@ -459,9 +451,8 @@ impl Bson {
459451

460452
/// Converts the Bson value into its [canonical extended JSON representation](https://docs.mongodb.com/manual/reference/mongodb-extended-json/).
461453
///
462-
/// Note: extended json encoding for `Decimal128` values is not supported without the
463-
/// "decimal128" feature flag. If this method is called on a case which contains a
464-
/// `Decimal128` value, it will panic.
454+
/// Note: extended json encoding for `Decimal128` values is not supported. If this method is
455+
/// called on a case which contains a `Decimal128` value, it will panic.
465456
pub fn into_canonical_extjson(self) -> Value {
466457
match self {
467458
Bson::Int32(i) => json!({ "$numberInt": i.to_string() }),
@@ -594,12 +585,6 @@ impl Bson {
594585
"$symbol": v.to_owned(),
595586
}
596587
}
597-
#[cfg(feature = "decimal128")]
598-
Bson::Decimal128(ref v) => {
599-
doc! {
600-
"$numberDecimal": (v.to_string())
601-
}
602-
}
603588
Bson::Undefined => {
604589
doc! {
605590
"$undefined": true,
@@ -683,25 +668,10 @@ impl Bson {
683668
_ => {}
684669
},
685670

686-
#[cfg(feature = "decimal128")]
687-
["$numberDecimal"] => {
688-
if let Ok(d) = doc.get_str("$numberDecimal") {
689-
if let Ok(d) = d.parse() {
690-
return Bson::Decimal128(d);
691-
}
692-
}
693-
}
694-
695671
["$numberDecimalBytes"] => {
696672
if let Ok(bytes) = doc.get_binary_generic("$numberDecimalBytes") {
697673
if let Ok(b) = bytes.clone().try_into() {
698-
#[cfg(not(feature = "decimal128"))]
699674
return Bson::Decimal128(Decimal128 { bytes: b });
700-
701-
#[cfg(feature = "decimal128")]
702-
unsafe {
703-
return Bson::Decimal128(Decimal128::from_raw_bytes_le(b));
704-
}
705675
}
706676
}
707677
}

src/de/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,13 @@ fn read_f64<R: Read + ?Sized>(reader: &mut R) -> Result<f64> {
162162

163163
/// Placeholder decoder for `Decimal128`. Reads 128 bits and just stores them, does no validation or
164164
/// parsing.
165-
#[cfg(not(feature = "decimal128"))]
166165
#[inline]
167166
fn read_f128<R: Read + ?Sized>(reader: &mut R) -> Result<Decimal128> {
168167
let mut buf = [0u8; 128 / 8];
169168
reader.read_exact(&mut buf)?;
170169
Ok(Decimal128 { bytes: buf })
171170
}
172171

173-
#[cfg(feature = "decimal128")]
174-
#[inline]
175-
fn read_f128<R: Read + ?Sized>(reader: &mut R) -> Result<Decimal128> {
176-
let mut local_buf = [0u8; 16];
177-
reader.read_exact(&mut local_buf)?;
178-
let val = unsafe { Decimal128::from_raw_bytes_le(local_buf) };
179-
Ok(val)
180-
}
181-
182172
fn deserialize_array<R: Read + ?Sized>(reader: &mut R, utf8_lossy: bool) -> Result<Array> {
183173
let mut arr = Array::new();
184174
let length = read_i32(reader)?;

src/de/raw.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -581,15 +581,7 @@ impl<'de> serde::de::Deserializer<'de> for Decimal128Deserializer {
581581
where
582582
V: serde::de::Visitor<'de>,
583583
{
584-
#[cfg(not(feature = "decimal128"))]
585-
{
586-
visitor.visit_bytes(&self.0.bytes)
587-
}
588-
589-
#[cfg(feature = "decimal128")]
590-
{
591-
visitor.visit_bytes(&self.0.to_raw_bytes_le())
592-
}
584+
visitor.visit_bytes(&self.0.bytes)
593585
}
594586

595587
serde::forward_to_deserialize_any! {

src/de/serde.rs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,10 @@ impl<'de> Visitor<'de> for BsonVisitor {
378378
}
379379

380380
"$numberDecimal" => {
381-
#[cfg(not(feature = "decimal128"))]
382-
{
383-
return Err(Error::custom(format!(
384-
"enable the experimental decimal128 feature flag to deserialize \
385-
decimal128 from string"
386-
)));
387-
}
388-
389-
#[cfg(feature = "decimal128")]
390-
{
391-
let s = visitor.next_value::<String>()?;
392-
return Ok(Bson::Decimal128(s.parse().map_err(|_| {
393-
Error::custom(format!("malformatted decimal128 string: {}", s))
394-
})?));
395-
}
381+
return Err(Error::custom(
382+
"deserializing decimal128 values from strings is not currently supported"
383+
.to_string(),
384+
));
396385
}
397386

398387
"$numberDecimalBytes" => {
@@ -403,17 +392,7 @@ impl<'de> Visitor<'de> for BsonVisitor {
403392
v.len()
404393
))
405394
})?;
406-
#[cfg(not(feature = "decimal128"))]
407-
{
408-
return Ok(Bson::Decimal128(Decimal128 { bytes: arr }));
409-
}
410-
411-
#[cfg(feature = "decimal128")]
412-
{
413-
unsafe {
414-
return Ok(Bson::Decimal128(Decimal128::from_raw_bytes_le(arr)));
415-
}
416-
}
395+
return Ok(Bson::Decimal128(Decimal128 { bytes: arr }));
417396
}
418397

419398
_ => {
@@ -982,7 +961,6 @@ impl<'de> Deserialize<'de> for Binary {
982961
}
983962
}
984963

985-
#[cfg(feature = "decimal128")]
986964
impl<'de> Deserialize<'de> for Decimal128 {
987965
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
988966
where

0 commit comments

Comments
 (0)