diff --git a/serde-tests/options.rs b/serde-tests/options.rs deleted file mode 100644 index 63324dc0..00000000 --- a/serde-tests/options.rs +++ /dev/null @@ -1,218 +0,0 @@ -use std::collections::HashMap; - -use bson::{doc, Bson, DeserializerOptions, SerializerOptions}; - -use serde::{ - ser::{ - SerializeMap, - SerializeSeq, - SerializeStruct, - SerializeStructVariant, - SerializeTupleStruct, - SerializeTupleVariant, - }, - Deserialize, - Serialize, -}; - -/// Type whose serialize and deserialize implementations assert that the (de)serializer -/// is not human readable. -#[derive(Deserialize)] -struct Foo { - a: i32, - unit: Unit, - tuple: Tuple, - map: Map, - unit_variant: Bar, - tuple_variant: Bar, - struct_variant: Bar, - seq: Seq, -} - -impl Serialize for Foo { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - assert!(!serializer.is_human_readable()); - - let mut state = serializer.serialize_struct("Foo", 7)?; - state.serialize_field("a", &self.a)?; - state.serialize_field("unit", &self.unit)?; - state.serialize_field("tuple", &self.tuple)?; - state.serialize_field("map", &self.map)?; - state.serialize_field("unit_variant", &self.unit_variant)?; - state.serialize_field("tuple_variant", &self.tuple_variant)?; - state.serialize_field("struct_variant", &self.struct_variant)?; - state.serialize_field("seq", &self.seq)?; - state.end() - } -} - -#[derive(Deserialize)] -enum Bar { - Unit, - Tuple(Unit), - Struct { a: Unit }, -} - -impl Serialize for Bar { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - assert!(!serializer.is_human_readable()); - match self { - Self::Unit => serializer.serialize_unit_variant("Bar", 0, "Unit"), - Self::Tuple(t) => { - let mut state = serializer.serialize_tuple_variant("Bar", 1, "Tuple", 1)?; - state.serialize_field(t)?; - state.end() - } - Self::Struct { a } => { - let mut state = serializer.serialize_struct_variant("Foo", 2, "Struct", 1)?; - state.serialize_field("a", a)?; - state.end() - } - } - } -} - -struct Unit; - -impl Serialize for Unit { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - assert!(!serializer.is_human_readable()); - serializer.serialize_unit_struct("Unit") - } -} - -impl<'de> Deserialize<'de> for Unit { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - assert!(!deserializer.is_human_readable()); - Ok(Unit) - } -} - -#[derive(Deserialize)] -struct Tuple(Unit); - -impl Serialize for Tuple { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - assert!(!serializer.is_human_readable()); - let mut state = serializer.serialize_tuple_struct("Tuple", 1)?; - state.serialize_field(&self.0)?; - state.end() - } -} - -struct Map { - map: HashMap, -} - -impl Serialize for Map { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - assert!(!serializer.is_human_readable()); - - let mut state = serializer.serialize_map(Some(self.map.len()))?; - for (k, v) in self.map.iter() { - state.serialize_entry(k, &v)?; - } - state.end() - } -} - -impl<'de> Deserialize<'de> for Map { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - assert!(!deserializer.is_human_readable()); - let map = Deserialize::deserialize(deserializer)?; - Ok(Self { map }) - } -} - -struct Seq { - seq: Vec, -} - -impl Serialize for Seq { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - assert!(!serializer.is_human_readable()); - - let mut state = serializer.serialize_seq(Some(self.seq.len()))?; - for v in self.seq.iter() { - state.serialize_element(&v)?; - } - state.end() - } -} - -impl<'de> Deserialize<'de> for Seq { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - assert!(!deserializer.is_human_readable()); - let v = Vec::::deserialize(deserializer)?; - Ok(Self { seq: v }) - } -} - -#[test] -fn to_bson_with_options() { - #[allow(deprecated)] - let options = SerializerOptions::builder().human_readable(false).build(); - - let mut hm = HashMap::new(); - hm.insert("ok".to_string(), Unit); - hm.insert("other".to_string(), Unit); - let f = Foo { - a: 5, - unit: Unit, - tuple: Tuple(Unit), - unit_variant: Bar::Unit, - tuple_variant: Bar::Tuple(Unit), - struct_variant: Bar::Struct { a: Unit }, - map: Map { map: hm }, - seq: Seq { - seq: vec![Unit, Unit], - }, - }; - bson::to_bson_with_options(&f, options).unwrap(); -} - -#[test] -fn from_bson_with_options() { - #[allow(deprecated)] - let options = DeserializerOptions::builder().human_readable(false).build(); - - let doc = doc! { - "a": 5, - "unit": Bson::Null, - "tuple": [Bson::Null], - "unit_variant": { "Unit": Bson::Null }, - "tuple_variant": { "Tuple": [Bson::Null] }, - "struct_variant": { "Struct": { "a": Bson::Null } }, - "map": { "a": Bson::Null, "b": Bson::Null }, - "seq": [Bson::Null, Bson::Null], - }; - - let _: Foo = bson::from_bson_with_options(doc.into(), options).unwrap(); -} diff --git a/serde-tests/test.rs b/serde-tests/test.rs index 44d55ac0..719f63c6 100644 --- a/serde-tests/test.rs +++ b/serde-tests/test.rs @@ -2,7 +2,6 @@ #![allow(clippy::vec_init_then_push)] mod json; -mod options; use pretty_assertions::assert_eq; use serde::{ @@ -19,7 +18,6 @@ use std::{ }; use bson::{ - bson, doc, oid::ObjectId, spec::BinarySubtype, @@ -28,7 +26,6 @@ use bson::{ DateTime, Decimal128, Deserializer, - DeserializerOptions, Document, JavaScriptCodeWithScope, RawArray, @@ -43,7 +40,6 @@ use bson::{ RawJavaScriptCodeWithScopeRef, RawRegexRef, Regex, - SerializerOptions, Timestamp, Uuid, }; @@ -86,25 +82,6 @@ where description ); - let non_human_readable_doc = bson::to_document_with_options( - &expected_value, - #[allow(deprecated)] - SerializerOptions::builder().human_readable(false).build(), - ) - .expect(description); - assert_eq!(&non_human_readable_doc, expected_doc, "{}", description); - assert_eq!( - expected_value, - &bson::from_document_with_options::( - non_human_readable_doc, - #[allow(deprecated)] - DeserializerOptions::builder().human_readable(false).build() - ) - .expect(description), - "{}", - description - ); - assert_eq!( &bson::from_reader::<_, T>(expected_bytes.as_slice()).expect(description), expected_value, @@ -1353,62 +1330,6 @@ fn hint_cleared() { assert_eq!(round_doc, doc! { "doc": doc_value, "binary": binary_value }); } -#[test] -fn non_human_readable() { - let bytes = vec![1, 2, 3, 4]; - let binary = RawBinaryRef { - bytes: &bytes, - subtype: BinarySubtype::BinaryOld, - }; - - let doc_bytes = bson::to_vec(&doc! { "a": "b", "array": [1, 2, 3] }).unwrap(); - let doc = RawDocument::from_bytes(doc_bytes.as_slice()).unwrap(); - let arr = doc.get_array("array").unwrap(); - let oid = ObjectId::new(); - let uuid = Uuid::new(); - - #[derive(Debug, Deserialize, Serialize)] - struct Foo<'a> { - #[serde(borrow)] - binary: RawBinaryRef<'a>, - #[serde(borrow)] - doc: &'a RawDocument, - #[serde(borrow)] - arr: &'a RawArray, - oid: ObjectId, - uuid: Uuid, - } - - let val = Foo { - binary, - doc, - arr, - oid, - uuid, - }; - - let human_readable = bson::to_bson(&val).unwrap(); - let non_human_readable = bson::to_bson_with_options( - &val, - #[allow(deprecated)] - SerializerOptions::builder().human_readable(false).build(), - ) - .unwrap(); - - let expected = bson!({ - "binary": Binary { bytes: bytes.clone(), subtype: BinarySubtype::BinaryOld }, - "doc": { - "a": "b", - "array": [1, 2, 3], - }, - "arr": [1, 2, 3], - "oid": oid, - "uuid": uuid - }); - assert_eq!(human_readable, expected); - assert_eq!(human_readable, non_human_readable); -} - #[test] fn invalid_length() { // This is a regression test for fuzzer-generated input (RUST-1240). diff --git a/src/de/mod.rs b/src/de/mod.rs index f9f6814c..68d943de 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -27,7 +27,7 @@ mod serde; pub use self::{ error::{Error, Result}, - serde::{Deserializer, DeserializerOptions}, + serde::Deserializer, }; use std::io::Read; @@ -38,6 +38,7 @@ use crate::{ spec::BinarySubtype, }; +#[rustfmt::skip] use ::serde::{ de::{DeserializeOwned, Error as _}, Deserialize, @@ -84,9 +85,7 @@ impl Timestamp { /// The [`Deserializer`] used by this function presents itself as human readable, whereas the /// one used in [`from_slice`] does not. This means that this function may deserialize differently /// than [`from_slice`] for types that change their deserialization logic depending on whether -/// the format is human readable or not. To deserialize from [`Bson`] with a deserializer that -/// presents itself as not human readable, use [`from_bson_with_options`] with -/// [`DeserializerOptions::human_readable`] set to false. +/// the format is human readable or not. pub fn from_bson(bson: Bson) -> Result where T: DeserializeOwned, @@ -102,38 +101,12 @@ where } } -/// Deserialize a `T` from the provided [`Bson`] value, configuring the underlying -/// deserializer with the provided options. -/// ``` -/// # use serde::Deserialize; -/// # use bson::{bson, DeserializerOptions}; -/// #[derive(Debug, Deserialize, PartialEq)] -/// struct MyData { -/// a: String, -/// } -/// -/// let bson = bson!({ "a": "hello" }); -/// let options = DeserializerOptions::builder().human_readable(false).build(); -/// let data: MyData = bson::from_bson_with_options(bson, options)?; -/// assert_eq!(data, MyData { a: "hello".to_string() }); -/// # Ok::<(), Box>(()) -/// ``` -pub fn from_bson_with_options(bson: Bson, options: DeserializerOptions) -> Result -where - T: DeserializeOwned, -{ - let de = Deserializer::new_with_options(bson, options); - Deserialize::deserialize(de) -} - /// Deserialize a `T` from the provided [`Document`]. /// /// The [`Deserializer`] used by this function presents itself as human readable, whereas the /// one used in [`from_slice`] does not. This means that this function may deserialize differently /// than [`from_slice`] for types that change their deserialization logic depending on whether -/// the format is human readable or not. To deserialize from [`Document`] with a deserializer that -/// presents itself as not human readable, use [`from_document_with_options`] with -/// [`DeserializerOptions::human_readable`] set to false. +/// the format is human readable or not. pub fn from_document(doc: Document) -> Result where T: DeserializeOwned, @@ -141,30 +114,6 @@ where from_bson(Bson::Document(doc)) } -/// Deserialize a `T` from the provided [`Document`], configuring the underlying -/// deserializer with the provided options. -/// ``` -/// # use serde::Deserialize; -/// # use bson::{doc, DeserializerOptions}; -/// #[derive(Debug, Deserialize, PartialEq)] -/// struct MyData { -/// a: String, -/// } -/// -/// let doc = doc! { "a": "hello" }; -/// let options = DeserializerOptions::builder().human_readable(false).build(); -/// let data: MyData = bson::from_document_with_options(doc, options)?; -/// assert_eq!(data, MyData { a: "hello".to_string() }); -/// # Ok::<(), Box>(()) -/// ``` -pub fn from_document_with_options(doc: Document, options: DeserializerOptions) -> Result -where - T: DeserializeOwned, -{ - let de = Deserializer::new_with_options(Bson::Document(doc), options); - Deserialize::deserialize(de) -} - pub(crate) fn reader_to_vec(mut reader: R) -> Result> { let mut buf = [0; 4]; reader.read_exact(&mut buf)?; diff --git a/src/de/raw.rs b/src/de/raw.rs index 69607bc6..6ec3e437 100644 --- a/src/de/raw.rs +++ b/src/de/raw.rs @@ -79,10 +79,9 @@ impl<'de> Deserializer<'de> { } Utf8LossyBson::JavaScriptCode(code) => visitor.visit_map(MapDeserializer::new( doc! { "$code": code }, - #[allow(deprecated)] - crate::DeserializerOptions::builder() - .human_readable(false) - .build(), + crate::de::serde::DeserializerOptions { + human_readable: Some(false), + }, )), Utf8LossyBson::JavaScriptCodeWithScope(jsc) => visitor.visit_map( CodeWithScopeAccess::new(BsonCow::Owned(jsc), hint, self.options.clone()), @@ -92,10 +91,9 @@ impl<'de> Deserializer<'de> { } Utf8LossyBson::Symbol(s) => visitor.visit_map(MapDeserializer::new( doc! { "$symbol": s }, - #[allow(deprecated)] - crate::DeserializerOptions::builder() - .human_readable(false) - .build(), + crate::de::serde::DeserializerOptions { + human_readable: Some(false), + }, )), }; } diff --git a/src/de/serde.rs b/src/de/serde.rs index ecf35935..bba415a4 100644 --- a/src/de/serde.rs +++ b/src/de/serde.rs @@ -580,44 +580,13 @@ pub struct Deserializer { options: DeserializerOptions, } -/// Options used to configure a [`Deserializer`]. These can also be passed into -/// [`crate::from_bson_with_options`] and [`crate::from_document_with_options`]. +/// Options used to configure a [`Deserializer`]. #[derive(Debug, Clone, Default)] #[non_exhaustive] -pub struct DeserializerOptions { +pub(crate) struct DeserializerOptions { /// Whether the [`Deserializer`] should present itself as human readable or not. - /// The default is true. - #[deprecated = "use bson::serde_helpers::HumanReadable"] - pub human_readable: Option, -} - -impl DeserializerOptions { - /// Create a builder struct used to construct a [`DeserializerOptions`]. - pub fn builder() -> DeserializerOptionsBuilder { - DeserializerOptionsBuilder { - options: Default::default(), - } - } -} - -/// Builder used to construct a [`DeserializerOptions`]. -pub struct DeserializerOptionsBuilder { - options: DeserializerOptions, -} - -impl DeserializerOptionsBuilder { - /// Set the value for [`DeserializerOptions::human_readable`]. - #[deprecated = "use bson::serde_helpers::HumanReadable"] - #[allow(deprecated)] - pub fn human_readable(mut self, val: impl Into>) -> Self { - self.options.human_readable = val.into(); - self - } - - /// Consume this builder and produce a [`DeserializerOptions`]. - pub fn build(self) -> DeserializerOptions { - self.options - } + /// The default is true. For internal use only. + pub(crate) human_readable: Option, } impl Deserializer { @@ -627,7 +596,7 @@ impl Deserializer { } /// Create a new [`Deserializer`] using the provided options. - pub fn new_with_options(value: Bson, options: DeserializerOptions) -> Self { + pub(crate) fn new_with_options(value: Bson, options: DeserializerOptions) -> Self { Deserializer { value: Some(value), options, diff --git a/src/lib.rs b/src/lib.rs index b7021b0f..5be35f0e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -289,16 +289,7 @@ pub use self::{ binary::Binary, bson::{Array, Bson, DbPointer, Document, JavaScriptCodeWithScope, Regex, Timestamp}, datetime::DateTime, - de::{ - from_bson, - from_bson_with_options, - from_document, - from_document_with_options, - from_reader, - from_slice, - Deserializer, - DeserializerOptions, - }, + de::{from_bson, from_document, from_reader, from_slice, Deserializer}, decimal128::Decimal128, raw::{ RawArray, @@ -313,16 +304,7 @@ pub use self::{ RawJavaScriptCodeWithScopeRef, RawRegexRef, }, - ser::{ - to_bson, - to_bson_with_options, - to_document, - to_document_with_options, - to_raw_document_buf, - to_vec, - Serializer, - SerializerOptions, - }, + ser::{to_bson, to_document, to_raw_document_buf, to_vec, Serializer}, uuid::{Uuid, UuidRepresentation}, }; diff --git a/src/ser/mod.rs b/src/ser/mod.rs index 10fb8037..65f6c9b1 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -27,18 +27,21 @@ mod serde; pub use self::{ error::{Error, Result}, - serde::{Serializer, SerializerOptions}, + serde::Serializer, }; use std::io::Write; +#[rustfmt::skip] +use ::serde::{ser::Error as SerdeError, Serialize}; + use crate::{ bson::{Bson, Document}, de::MAX_BSON_SIZE, + ser::serde::SerializerOptions, spec::BinarySubtype, RawDocumentBuf, }; -use ::serde::{ser::Error as SerdeError, Serialize}; pub(crate) fn write_string(buf: &mut Vec, s: &str) { buf.extend(&(s.len() as i32 + 1).to_le_bytes()); @@ -109,9 +112,7 @@ fn write_binary(mut writer: W, bytes: &[u8], subtype: BinarySubtype) - /// The [`Serializer`] used by this function presents itself as human readable, whereas the /// one used in [`to_vec`] does not. This means that this function will produce different BSON than /// [`to_vec`] for types that change their serialization output depending on whether -/// the format is human readable or not. To serialize to a [`Document`] with a serializer that -/// presents itself as not human readable, use [`to_bson_with_options`] with -/// [`SerializerOptions::human_readable`] set to false. +/// the format is human readable or not. pub fn to_bson(value: &T) -> Result where T: Serialize + ?Sized, @@ -125,23 +126,8 @@ where value.serialize(ser) } -/// Encode a `T` into a [`Bson`] value, configuring the underlying serializer with the provided -/// options. -/// ``` -/// # use serde::Serialize; -/// # use bson::{bson, SerializerOptions}; -/// #[derive(Debug, Serialize)] -/// struct MyData { -/// a: String, -/// } -/// -/// let data = MyData { a: "ok".to_string() }; -/// let options = SerializerOptions::builder().human_readable(false).build(); -/// let bson = bson::to_bson_with_options(&data, options)?; -/// assert_eq!(bson, bson!({ "a": "ok" })); -/// # Ok::<(), Box>(()) -/// ``` -pub fn to_bson_with_options(value: &T, options: SerializerOptions) -> Result +/// Internal-only method to serialize data to BSON with the given options. +pub(crate) fn to_bson_with_options(value: &T, options: SerializerOptions) -> Result where T: Serialize + ?Sized, { @@ -154,37 +140,12 @@ where /// The [`Serializer`] used by this function presents itself as human readable, whereas the /// one used in [`to_vec`] does not. This means that this function will produce different BSON than /// [`to_vec`] for types that change their serialization output depending on whether -/// the format is human readable or not. To serialize to a [`Document`] with a serializer that -/// presents itself as not human readable, use [`to_document_with_options`] with -/// [`SerializerOptions::human_readable`] set to false. +/// the format is human readable or not. pub fn to_document(value: &T) -> Result where T: Serialize + ?Sized, { - to_document_with_options(value, Default::default()) -} - -/// Encode a `T` into a [`Document`], configuring the underlying serializer with the provided -/// options. -/// ``` -/// # use serde::Serialize; -/// # use bson::{doc, SerializerOptions}; -/// #[derive(Debug, Serialize)] -/// struct MyData { -/// a: String, -/// } -/// -/// let data = MyData { a: "ok".to_string() }; -/// let options = SerializerOptions::builder().human_readable(false).build(); -/// let doc = bson::to_document_with_options(&data, options)?; -/// assert_eq!(doc, doc! { "a": "ok" }); -/// # Ok::<(), Box>(()) -/// ``` -pub fn to_document_with_options(value: &T, options: SerializerOptions) -> Result -where - T: Serialize + ?Sized, -{ - match to_bson_with_options(value, options)? { + match to_bson(value)? { Bson::Document(doc) => Ok(doc), bson => Err(Error::SerializationError { message: format!( diff --git a/src/ser/serde.rs b/src/ser/serde.rs index 469babee..053f1e93 100644 --- a/src/ser/serde.rs +++ b/src/ser/serde.rs @@ -114,40 +114,10 @@ pub struct Serializer { /// Options used to configure a [`Serializer`]. #[derive(Debug, Clone, Default)] #[non_exhaustive] -pub struct SerializerOptions { +pub(crate) struct SerializerOptions { /// Whether the [`Serializer`] should present itself as human readable or not. - /// The default value is true. - #[deprecated = "use bson::serde_helpers::HumanReadable"] - pub human_readable: Option, -} - -impl SerializerOptions { - /// Create a builder used to construct a new [`SerializerOptions`]. - pub fn builder() -> SerializerOptionsBuilder { - SerializerOptionsBuilder { - options: Default::default(), - } - } -} - -/// A builder used to construct new [`SerializerOptions`] structs. -pub struct SerializerOptionsBuilder { - options: SerializerOptions, -} - -impl SerializerOptionsBuilder { - /// Set the value for [`SerializerOptions::is_human_readable`]. - #[deprecated = "use bson::serde_helpers::HumanReadable"] - #[allow(deprecated)] - pub fn human_readable(mut self, value: impl Into>) -> Self { - self.options.human_readable = value.into(); - self - } - - /// Consume this builder and produce a [`SerializerOptions`]. - pub fn build(self) -> SerializerOptions { - self.options - } + /// The default value is true. For internal use only. + pub(crate) human_readable: Option, } impl Serializer { @@ -160,7 +130,7 @@ impl Serializer { } /// Construct a new [`Serializer`] configured with the provided [`SerializerOptions`]. - pub fn new_with_options(options: SerializerOptions) -> Self { + pub(crate) fn new_with_options(options: SerializerOptions) -> Self { Serializer { options } } } @@ -348,7 +318,6 @@ impl ser::Serializer for Serializer { b ))), }, - #[allow(deprecated)] HUMAN_READABLE_NEWTYPE => { self.options.human_readable = Some(true); value.serialize(self) @@ -452,7 +421,6 @@ impl ser::Serializer for Serializer { }) } - #[allow(deprecated)] fn is_human_readable(&self) -> bool { self.options.human_readable.unwrap_or(true) } diff --git a/src/serde_helpers.rs b/src/serde_helpers.rs index 56702b8e..98b2e00b 100644 --- a/src/serde_helpers.rs +++ b/src/serde_helpers.rs @@ -847,10 +847,8 @@ pub mod timestamp_as_u32 { } /// Wrapping a type in `HumanReadable` signals to the BSON serde integration that it and all -/// recursively contained types should be handled as if -/// [`SerializerOptions::human_readable`](crate::SerializerOptions::human_readable) and -/// [`DeserializerOptions::human_readable`](crate::DeserializerOptions::human_readable) are -/// set to `true`. +/// recursively contained types should be serialized to and deserialized from their human-readable +/// formats. #[derive(PartialEq, Eq, PartialOrd, Ord, Debug)] pub struct HumanReadable(pub T); diff --git a/src/tests/serde_helpers.rs b/src/tests/serde_helpers.rs index 54df88cf..817b8d88 100644 --- a/src/tests/serde_helpers.rs +++ b/src/tests/serde_helpers.rs @@ -78,6 +78,7 @@ fn human_readable_wrapper() { struct SubData { value: Detector, } + let data = Data { first: HumanReadable(Detector::new()), outer: Detector::new(), @@ -86,34 +87,19 @@ fn human_readable_wrapper() { value: Detector::new(), }), }; - let bson = crate::to_bson_with_options( - &data, - #[allow(deprecated)] - crate::SerializerOptions::builder() - .human_readable(false) - .build(), - ) - .unwrap(); - assert_eq!( - bson.as_document().unwrap(), - &doc! { - "first": "human readable", - "outer": "not human readable", - "wrapped": "human readable", - "inner": { - "value": "human readable", - } + // use the raw serializer, which is non-human-readable + let data_doc = crate::to_raw_document_buf(&data).unwrap(); + let expected_data_doc = rawdoc! { + "first": "human readable", + "outer": "not human readable", + "wrapped": "human readable", + "inner": { + "value": "human readable", } - ); - - let tripped: Data = crate::from_bson_with_options( - bson, - #[allow(deprecated)] - crate::DeserializerOptions::builder() - .human_readable(false) - .build(), - ) - .unwrap(); + }; + assert_eq!(data_doc, expected_data_doc); + + let tripped: Data = crate::from_slice(expected_data_doc.as_bytes()).unwrap(); let expected = Data { first: HumanReadable(Detector { serialized_as: true, @@ -135,10 +121,6 @@ fn human_readable_wrapper() { }), }; assert_eq!(&tripped, &expected); - - let bytes = crate::to_vec(&data).unwrap(); - let raw_tripped: Data = crate::from_slice(&bytes).unwrap(); - assert_eq!(&raw_tripped, &expected); } #[test]