Skip to content

Commit 2d5e6c8

Browse files
authored
RUST-960 Deprecate decimal128 feature flag (#288)
1 parent 8645dd0 commit 2d5e6c8

File tree

7 files changed

+20
-3
lines changed

7 files changed

+20
-3
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ exclude = [
3434
default = []
3535
# attempt to encode unsigned types in signed types
3636
u2i = []
37-
# Decimal128 in BSON 1.1
37+
# Experimental / unstable Decimal128 support
38+
# Note: this feature is deprecated and will be removed in 2.0.0.
39+
# The feature is not recommended for use as it causes decimal128
40+
# values to be serialized incorrectly to BSON.
3841
decimal128 = ["decimal"]
3942

4043
[lib]

src/de/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ fn read_f128<R: Read + ?Sized>(reader: &mut R) -> Result<Decimal128> {
162162
}
163163

164164
#[cfg(feature = "decimal128")]
165+
#[allow(deprecated)]
165166
#[inline]
166167
fn read_f128<R: Read + ?Sized>(reader: &mut R) -> Result<Decimal128> {
167168
let mut local_buf = [0u8; 16];

src/decimal128.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ use std::fmt;
1010
/// deserialized from existing documents that contain BSON decimal128s.
1111
///
1212
/// Experimental functionality can be enabled through the usage of the `"decimal128"`
13-
/// feature flag. Note that the API and behavior of such functionality are unstable and
14-
/// subject to change.
13+
/// feature flag. The flag is not recommended for use however, as it causes `Decimal128` values to
14+
/// serialize to BSON incorrectly. See [this issue](https://github.com/mongodb/bson-rust/issues/282#issuecomment-889958970) for
15+
/// more information.
16+
///
17+
/// Note that the API and behavior of the feature-gated functionality are unstable and subject to
18+
/// change, and the feature flag will be removed completely in 2.0.0.
1519
#[derive(Clone, PartialEq, PartialOrd)]
1620
pub struct Decimal128 {
1721
#[cfg(not(feature = "decimal128"))]
@@ -23,6 +27,8 @@ pub struct Decimal128 {
2327
}
2428

2529
#[cfg(feature = "decimal128")]
30+
#[deprecated = "The feature-gated decimal128 implementation serializes to BSON incorrectly and \
31+
should not be used. It will be removed completely in 2.0.0"]
2632
impl Decimal128 {
2733
/// Construct a `Decimal128` from string.
2834
///
@@ -231,6 +237,7 @@ impl fmt::LowerExp for Decimal128 {
231237
}
232238

233239
#[cfg(feature = "decimal128")]
240+
#[allow(deprecated)]
234241
impl std::str::FromStr for Decimal128 {
235242
type Err = ();
236243
fn from_str(s: &str) -> Result<Decimal128, ()> {
@@ -253,6 +260,7 @@ impl From<d128> for Decimal128 {
253260
}
254261

255262
#[cfg(feature = "decimal128")]
263+
#[allow(deprecated)]
256264
impl Default for Decimal128 {
257265
fn default() -> Decimal128 {
258266
Decimal128::zero()
@@ -261,6 +269,7 @@ impl Default for Decimal128 {
261269

262270
#[cfg(test)]
263271
#[cfg(feature = "decimal128")]
272+
#[allow(deprecated)]
264273
mod test {
265274
use super::*;
266275

src/ser/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ fn write_f64<W: Write + ?Sized>(writer: &mut W, val: f64) -> Result<()> {
7979
}
8080

8181
#[cfg(feature = "decimal128")]
82+
#[allow(deprecated)]
8283
#[inline]
8384
fn write_f128<W: Write + ?Sized>(writer: &mut W, val: Decimal128) -> Result<()> {
8485
let raw = val.to_raw_bytes_le();

src/tests/modules/ordered.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ fn ordered_insert_shorthand() {
5050
}
5151

5252
#[cfg(feature = "decimal128")]
53+
#[allow(deprecated)]
5354
fn test_decimal128(doc: &mut Document) {
5455
let _guard = LOCK.run_concurrently();
5556
let dec = Decimal128::from_str("968E+1");

src/tests/modules/ser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ fn int32() {
6969
}
7070

7171
#[cfg(feature = "decimal128")]
72+
#[allow(deprecated)]
7273
#[test]
7374
fn dec128() {
7475
let _guard = LOCK.run_concurrently();

src/tests/modules/serializer_deserializer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ fn test_deserialize_multiply_overflows_issue64() {
386386
}
387387

388388
#[cfg(feature = "decimal128")]
389+
#[allow(deprecated)]
389390
#[test]
390391
fn test_serialize_deserialize_decimal128() {
391392
let _guard = LOCK.run_concurrently();

0 commit comments

Comments
 (0)