Skip to content

RUST-960 Remove the decimal128 feature flag #287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,6 @@ functions:
${PREPARE_SHELL}
.evergreen/run-tests-u2i.sh

"run decimal128 tests":
- command: shell.exec
type: test
params:
shell: bash
working_dir: "src"
script: |
${PREPARE_SHELL}
.evergreen/run-tests-decimal128.sh

"compile only":
- command: shell.exec
type: test
Expand Down Expand Up @@ -160,10 +150,6 @@ tasks:
commands:
- func: "run u2i tests"

- name: "test-decimal128"
commands:
- func: "run decimal128 tests"

- name: "compile-only"
commands:
- func: "compile only"
Expand Down Expand Up @@ -197,7 +183,6 @@ buildvariants:
tasks:
- name: "test"
- name: "test-u2i"
- name: "test-decimal128"

- matrix_name: "compile only"
matrix_spec:
Expand Down
9 changes: 0 additions & 9 deletions .evergreen/run-tests-decimal128.sh

This file was deleted.

7 changes: 0 additions & 7 deletions .evergreen/run-tests-serde.sh

This file was deleted.

6 changes: 0 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ chrono-0_4 = []
uuid-0_8 = []
# attempt to encode unsigned types in signed types
u2i = []
# Decimal128 in BSON 1.1
decimal128 = ["decimal"]

[lib]
name = "bson"
Expand All @@ -53,7 +51,6 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
indexmap = "1.6.2"
hex = "0.4.2"
decimal = { version = "2.1.0", default_features = false, optional = true }
base64 = "0.13.0"
lazy_static = "1.4.0"
uuid = "0.8.1"
Expand All @@ -64,6 +61,3 @@ assert_matches = "1.2"
serde_bytes = "0.11"
pretty_assertions = "0.6.1"
chrono = { version = "0.4", features = ["serde"] }

[package.metadata.docs.rs]
features = ["decimal128"]
1 change: 0 additions & 1 deletion serde-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ edition = "2018"

[features]
u2i = ["bson/u2i"]
decimal128 = ["bson/decimal128"]

[dependencies]
bson = { path = ".." }
Expand Down
8 changes: 1 addition & 7 deletions serde-tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use std::{
collections::{BTreeMap, HashSet},
};

#[cfg(feature = "decimal128")]
use bson::Decimal128;
use bson::{
doc,
oid::ObjectId,
Expand Down Expand Up @@ -749,16 +747,12 @@ fn all_types() {
let oid = ObjectId::new();
let subdoc = doc! { "k": true, "b": { "hello": "world" } };

#[cfg(not(feature = "decimal128"))]
let decimal = {
let bytes = hex::decode("18000000136400D0070000000000000000000000003A3000").unwrap();
let d = Document::from_reader(bytes.as_slice()).unwrap();
d.get("d").unwrap().clone()
};

#[cfg(feature = "decimal128")]
let decimal = Bson::Decimal128(Decimal128::from_str("2.000"));

let doc = doc! {
"x": 1,
"y": 2_i64,
Expand Down Expand Up @@ -902,7 +896,7 @@ fn u2i() {
"u_32": 1234_i64,
"u_32_max": u32::MAX as i64,
"u_64": 12345_i64,
"i_64_max": i64::MAX as u64,
"i_64_max": i64::MAX,
};

run_test(&v, &expected, "u2i - valid");
Expand Down
38 changes: 4 additions & 34 deletions src/bson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,7 @@ impl From<Bson> for Value {
impl Bson {
/// Converts the Bson value into its [relaxed extended JSON representation](https://docs.mongodb.com/manual/reference/mongodb-extended-json/).
///
/// Note: extended json encoding for `Decimal128` values is not supported without the
/// "decimal128" feature flag. If this method is called on a case which contains a
/// `Decimal128` value, it will panic.
/// Note: If this method is called on a case which contains a `Decimal128` value, it will panic.
pub fn into_relaxed_extjson(self) -> Value {
match self {
Bson::Double(v) if v.is_nan() => {
Expand Down Expand Up @@ -433,13 +431,7 @@ impl Bson {
"$date": { "$numberLong": v.timestamp_millis().to_string() },
}),
Bson::Symbol(v) => json!({ "$symbol": v }),
#[cfg(feature = "decimal128")]
Bson::Decimal128(ref v) => json!({ "$numberDecimal": v.to_string() }),
#[cfg(not(feature = "decimal128"))]
Bson::Decimal128(_) => panic!(
"Decimal128 extended JSON not implemented yet. Use the decimal128 feature to \
enable experimental support for it."
),
Bson::Decimal128(_) => panic!("Decimal128 extended JSON not implemented yet."),
Bson::Undefined => json!({ "$undefined": true }),
Bson::MinKey => json!({ "$minKey": 1 }),
Bson::MaxKey => json!({ "$maxKey": 1 }),
Expand All @@ -459,9 +451,8 @@ impl Bson {

/// Converts the Bson value into its [canonical extended JSON representation](https://docs.mongodb.com/manual/reference/mongodb-extended-json/).
///
/// Note: extended json encoding for `Decimal128` values is not supported without the
/// "decimal128" feature flag. If this method is called on a case which contains a
/// `Decimal128` value, it will panic.
/// Note: extended json encoding for `Decimal128` values is not supported. If this method is
/// called on a case which contains a `Decimal128` value, it will panic.
pub fn into_canonical_extjson(self) -> Value {
match self {
Bson::Int32(i) => json!({ "$numberInt": i.to_string() }),
Expand Down Expand Up @@ -594,12 +585,6 @@ impl Bson {
"$symbol": v.to_owned(),
}
}
#[cfg(feature = "decimal128")]
Bson::Decimal128(ref v) => {
doc! {
"$numberDecimal": (v.to_string())
}
}
Bson::Undefined => {
doc! {
"$undefined": true,
Expand Down Expand Up @@ -683,25 +668,10 @@ impl Bson {
_ => {}
},

#[cfg(feature = "decimal128")]
["$numberDecimal"] => {
if let Ok(d) = doc.get_str("$numberDecimal") {
if let Ok(d) = d.parse() {
return Bson::Decimal128(d);
}
}
}

["$numberDecimalBytes"] => {
if let Ok(bytes) = doc.get_binary_generic("$numberDecimalBytes") {
if let Ok(b) = bytes.clone().try_into() {
#[cfg(not(feature = "decimal128"))]
return Bson::Decimal128(Decimal128 { bytes: b });

#[cfg(feature = "decimal128")]
unsafe {
return Bson::Decimal128(Decimal128::from_raw_bytes_le(b));
}
}
}
}
Expand Down
10 changes: 0 additions & 10 deletions src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,13 @@ fn read_f64<R: Read + ?Sized>(reader: &mut R) -> Result<f64> {

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

#[cfg(feature = "decimal128")]
#[inline]
fn read_f128<R: Read + ?Sized>(reader: &mut R) -> Result<Decimal128> {
let mut local_buf = [0u8; 16];
reader.read_exact(&mut local_buf)?;
let val = unsafe { Decimal128::from_raw_bytes_le(local_buf) };
Ok(val)
}

fn deserialize_array<R: Read + ?Sized>(reader: &mut R, utf8_lossy: bool) -> Result<Array> {
let mut arr = Array::new();
let length = read_i32(reader)?;
Expand Down
10 changes: 1 addition & 9 deletions src/de/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,15 +581,7 @@ impl<'de> serde::de::Deserializer<'de> for Decimal128Deserializer {
where
V: serde::de::Visitor<'de>,
{
#[cfg(not(feature = "decimal128"))]
{
visitor.visit_bytes(&self.0.bytes)
}

#[cfg(feature = "decimal128")]
{
visitor.visit_bytes(&self.0.to_raw_bytes_le())
}
visitor.visit_bytes(&self.0.bytes)
}

serde::forward_to_deserialize_any! {
Expand Down
32 changes: 5 additions & 27 deletions src/de/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,21 +378,10 @@ impl<'de> Visitor<'de> for BsonVisitor {
}

"$numberDecimal" => {
#[cfg(not(feature = "decimal128"))]
{
return Err(Error::custom(format!(
"enable the experimental decimal128 feature flag to deserialize \
decimal128 from string"
)));
}

#[cfg(feature = "decimal128")]
{
let s = visitor.next_value::<String>()?;
return Ok(Bson::Decimal128(s.parse().map_err(|_| {
Error::custom(format!("malformatted decimal128 string: {}", s))
})?));
}
return Err(Error::custom(
"deserializing decimal128 values from strings is not currently supported"
.to_string(),
));
}

"$numberDecimalBytes" => {
Expand All @@ -403,17 +392,7 @@ impl<'de> Visitor<'de> for BsonVisitor {
v.len()
))
})?;
#[cfg(not(feature = "decimal128"))]
{
return Ok(Bson::Decimal128(Decimal128 { bytes: arr }));
}

#[cfg(feature = "decimal128")]
{
unsafe {
return Ok(Bson::Decimal128(Decimal128::from_raw_bytes_le(arr)));
}
}
return Ok(Bson::Decimal128(Decimal128 { bytes: arr }));
}

_ => {
Expand Down Expand Up @@ -982,7 +961,6 @@ impl<'de> Deserialize<'de> for Binary {
}
}

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