Skip to content

RUST-1763 deprecate CollectionOptions::human_readable_serialization #957

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 1 commit into from
Sep 18, 2023
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
1 change: 1 addition & 0 deletions src/coll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ impl<T> Collection<T> {
let write_concern = options
.write_concern
.or_else(|| db.write_concern().cloned());
#[allow(deprecated)]
let human_readable_serialization = options.human_readable_serialization.unwrap_or_default();

Self {
Expand Down
54 changes: 34 additions & 20 deletions src/coll/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,41 @@ use crate::{
serde_util,
};

/// These are the valid options for creating a [`Collection`](../struct.Collection.html) with
/// [`Database::collection_with_options`](../struct.Database.html#method.collection_with_options).
#[derive(Clone, Debug, Default, Deserialize, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct CollectionOptions {
/// The default read preference for operations.
pub selection_criteria: Option<SelectionCriteria>,

/// The default read concern for operations.
pub read_concern: Option<ReadConcern>,

/// The default write concern for operations.
pub write_concern: Option<WriteConcern>,

/// Sets the [`bson::SerializerOptions::human_readable`] option for the [`Bson`] serializer.
/// The default value is `false`.
/// Note: Specifying `true` for this value will decrease the performance of insert operations.
pub human_readable_serialization: Option<bool>,
// Generated code for `Deserialize` or `TypedBuilder` causes a deprecation warning; annotating the
// field or struct doesn't fix it because that annotation isn't propagated by the code generator.
// This works around that by defining it in a non-pub module and immediately re-exporting that
// module's contents.
#[allow(deprecated)]
mod suppress_warning {
use super::*;

/// These are the valid options for creating a [`Collection`](../struct.Collection.html) with
/// [`Database::collection_with_options`](../struct.Database.html#method.
/// collection_with_options).
#[derive(Clone, Debug, Default, Deserialize, TypedBuilder)]
#[builder(field_defaults(default, setter(into)))]
#[serde(rename_all = "camelCase")]
#[non_exhaustive]
pub struct CollectionOptions {
/// The default read preference for operations.
pub selection_criteria: Option<SelectionCriteria>,

/// The default read concern for operations.
pub read_concern: Option<ReadConcern>,

/// The default write concern for operations.
pub write_concern: Option<WriteConcern>,

/// Sets the [`bson::SerializerOptions::human_readable`] option for the [`Bson`]
/// serializer. The default value is `false`.
/// Note: Specifying `true` for this value will decrease the performance of insert
/// operations.
#[deprecated = "This is a workaround for a potential bug related to RUST-1687, and should \
not be used in new code."]
pub human_readable_serialization: Option<bool>,
}
}
pub use suppress_warning::*;

/// Specifies whether a
/// [`Collection::find_one_and_replace`](../struct.Collection.html#method.find_one_and_replace) and
Expand Down