Skip to content

Commit ec3a644

Browse files
authored
RUST-1764 Drop human_readable options in favor of HumanReadable (#1064)
1 parent 8c62064 commit ec3a644

File tree

9 files changed

+14
-74
lines changed

9 files changed

+14
-74
lines changed

src/action/find_and_modify.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::{
2020
UpdateOrReplace,
2121
},
2222
options::WriteConcern,
23-
serde_util,
2423
ClientSession,
2524
Collection,
2625
};
@@ -105,10 +104,7 @@ impl<T: Serialize + DeserializeOwned + Send + Sync> Collection<T> {
105104
FindOneAndReplace {
106105
coll: self,
107106
filter,
108-
replacement: serde_util::to_raw_document_buf_with_options(
109-
replacement.borrow(),
110-
self.human_readable_serialization(),
111-
),
107+
replacement: bson::to_raw_document_buf(replacement.borrow()).map_err(Into::into),
112108
options: None,
113109
session: None,
114110
}

src/action/insert_many.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::{
99
operation::Insert as Op,
1010
options::WriteConcern,
1111
results::InsertManyResult,
12-
serde_util,
1312
ClientSession,
1413
Collection,
1514
};
@@ -30,12 +29,11 @@ impl<T: Serialize + Send + Sync> Collection<T> {
3029
/// `await` will return d[`Result<InsertManyResult>`].
3130
#[deeplink]
3231
pub fn insert_many(&self, docs: impl IntoIterator<Item = impl Borrow<T>>) -> InsertMany {
33-
let human_readable = self.human_readable_serialization();
3432
InsertMany {
3533
coll: CollRef::new(self),
3634
docs: docs
3735
.into_iter()
38-
.map(|v| serde_util::to_raw_document_buf_with_options(v.borrow(), human_readable))
36+
.map(|v| bson::to_raw_document_buf(v.borrow()).map_err(Into::into))
3937
.collect(),
4038
options: None,
4139
session: None,

src/action/insert_one.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::{
99
operation::Insert as Op,
1010
options::WriteConcern,
1111
results::InsertOneResult,
12-
serde_util,
1312
ClientSession,
1413
Collection,
1514
};
@@ -32,10 +31,7 @@ impl<T: Serialize + Send + Sync> Collection<T> {
3231
pub fn insert_one(&self, doc: impl Borrow<T>) -> InsertOne {
3332
InsertOne {
3433
coll: CollRef::new(self),
35-
doc: serde_util::to_raw_document_buf_with_options(
36-
doc.borrow(),
37-
self.human_readable_serialization(),
38-
),
34+
doc: bson::to_raw_document_buf(doc.borrow()).map_err(Into::into),
3935
options: None,
4036
session: None,
4137
}

src/action/replace_one.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::{
1010
operation::Update as Op,
1111
options::WriteConcern,
1212
results::UpdateResult,
13-
serde_util,
1413
ClientSession,
1514
Collection,
1615
};
@@ -31,10 +30,7 @@ impl<T: Serialize + Send + Sync> Collection<T> {
3130
ReplaceOne {
3231
coll: CollRef::new(self),
3332
query,
34-
replacement: serde_util::to_raw_document_buf_with_options(
35-
replacement.borrow(),
36-
self.human_readable_serialization(),
37-
),
33+
replacement: bson::to_raw_document_buf(replacement.borrow()).map_err(Into::into),
3834
options: None,
3935
session: None,
4036
}

src/coll.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ struct CollectionInner {
101101
selection_criteria: Option<SelectionCriteria>,
102102
read_concern: Option<ReadConcern>,
103103
write_concern: Option<WriteConcern>,
104-
human_readable_serialization: bool,
105104
}
106105

107106
impl<T> Collection<T>
@@ -119,8 +118,6 @@ where
119118
let write_concern = options
120119
.write_concern
121120
.or_else(|| db.write_concern().cloned());
122-
#[allow(deprecated)]
123-
let human_readable_serialization = options.human_readable_serialization.unwrap_or_default();
124121

125122
Self {
126123
inner: Arc::new(CollectionInner {
@@ -130,7 +127,6 @@ where
130127
selection_criteria,
131128
read_concern,
132129
write_concern,
133-
human_readable_serialization,
134130
}),
135131
_phantom: Default::default(),
136132
}
@@ -213,10 +209,6 @@ where
213209
self.client().execute_operation(op, None).await?;
214210
Ok(())
215211
}
216-
217-
pub(crate) fn human_readable_serialization(&self) -> bool {
218-
self.inner.human_readable_serialization
219-
}
220212
}
221213

222214
/// A struct modeling the canonical name for a collection in MongoDB.

src/coll/options.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use crate::{
1717
// field or struct doesn't fix it because that annotation isn't propagated by the code generator.
1818
// This works around that by defining it in a non-pub module and immediately re-exporting that
1919
// module's contents.
20-
#[allow(deprecated)]
2120
mod suppress_warning {
2221
use super::*;
2322

@@ -36,14 +35,6 @@ mod suppress_warning {
3635

3736
/// The default write concern for operations.
3837
pub write_concern: Option<WriteConcern>,
39-
40-
/// Sets the [`bson::SerializerOptions::human_readable`] option for the [`Bson`]
41-
/// serializer. The default value is `false`.
42-
/// Note: Specifying `true` for this value will decrease the performance of insert
43-
/// operations.
44-
#[deprecated = "This is a workaround for a potential bug related to RUST-1687, and should \
45-
not be used in new code."]
46-
pub human_readable_serialization: Option<bool>,
4738
}
4839
}
4940
pub use suppress_warning::*;

src/serde_util.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::time::Duration;
22

3-
use bson::SerializerOptions;
43
use serde::{Deserialize, Deserializer, Serialize, Serializer};
54

65
use crate::{
7-
bson::{doc, Bson, Document, RawDocumentBuf},
6+
bson::{doc, Bson, Document},
87
bson_util::get_u64,
98
error::{Error, Result},
109
options::WriteConcern,
@@ -162,22 +161,6 @@ where
162161
Ok(Some(date_time))
163162
}
164163

165-
pub(crate) fn to_raw_document_buf_with_options<T: Serialize>(
166-
doc: &T,
167-
human_readable_serialization: bool,
168-
) -> Result<RawDocumentBuf> {
169-
let raw_doc = if human_readable_serialization {
170-
let doc = bson::to_document_with_options(
171-
doc,
172-
SerializerOptions::builder().human_readable(true).build(),
173-
)?;
174-
RawDocumentBuf::from_document(&doc)?
175-
} else {
176-
bson::to_raw_document_buf(doc)?
177-
};
178-
Ok(raw_doc)
179-
}
180-
181164
pub(crate) fn write_concern_is_empty(write_concern: &Option<WriteConcern>) -> bool {
182165
write_concern
183166
.as_ref()

src/test/coll.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
Client,
77
Namespace,
88
};
9-
use bson::{rawdoc, RawDocumentBuf};
9+
use bson::{rawdoc, serde_helpers::HumanReadable, RawDocumentBuf};
1010
use futures::stream::{StreamExt, TryStreamExt};
1111
use once_cell::sync::Lazy;
1212
use semver::VersionReq;
@@ -1159,13 +1159,8 @@ async fn configure_human_readable_serialization() {
11591159

11601160
let client = TestClient::new().await;
11611161

1162-
let collection_options = CollectionOptions::builder()
1163-
.human_readable_serialization(false)
1164-
.build();
1165-
1166-
let non_human_readable_collection: Collection<Data> = client
1167-
.database("db")
1168-
.collection_with_options("nonhumanreadable", collection_options);
1162+
let non_human_readable_collection: Collection<Data> =
1163+
client.database("db").collection("nonhumanreadable");
11691164
non_human_readable_collection.drop().await.unwrap();
11701165

11711166
non_human_readable_collection
@@ -1204,20 +1199,15 @@ async fn configure_human_readable_serialization() {
12041199
.unwrap();
12051200
assert!(doc.get_binary_generic("s").is_ok());
12061201

1207-
let collection_options = CollectionOptions::builder()
1208-
.human_readable_serialization(true)
1209-
.build();
1210-
1211-
let human_readable_collection: Collection<Data> = client
1212-
.database("db")
1213-
.collection_with_options("humanreadable", collection_options);
1202+
let human_readable_collection: Collection<HumanReadable<Data>> =
1203+
client.database("db").collection("humanreadable");
12141204
human_readable_collection.drop().await.unwrap();
12151205

12161206
human_readable_collection
1217-
.insert_one(Data {
1207+
.insert_one(HumanReadable(Data {
12181208
id: 0,
12191209
s: StringOrBytes("human readable!".into()),
1220-
})
1210+
}))
12211211
.await
12221212
.unwrap();
12231213

@@ -1231,10 +1221,10 @@ async fn configure_human_readable_serialization() {
12311221
human_readable_collection
12321222
.replace_one(
12331223
doc! { "id": 0 },
1234-
Data {
1224+
HumanReadable(Data {
12351225
id: 1,
12361226
s: StringOrBytes("human readable!".into()),
1237-
},
1227+
}),
12381228
)
12391229
.await
12401230
.unwrap();

src/test/spec/unified_runner/test_file.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,11 @@ impl CollectionOrDatabaseOptions {
373373
}
374374
}
375375

376-
#[allow(deprecated)]
377376
pub(crate) fn as_collection_options(&self) -> CollectionOptions {
378377
CollectionOptions {
379378
read_concern: self.read_concern.clone(),
380379
selection_criteria: self.selection_criteria.clone(),
381380
write_concern: self.write_concern.clone(),
382-
human_readable_serialization: None,
383381
}
384382
}
385383
}

0 commit comments

Comments
 (0)