From 8aa30ccdff09d08d71b0df3c86d909306f634853 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Tue, 19 Aug 2025 13:04:43 +0100 Subject: [PATCH 1/4] RUST-2251 document and tidy up serde helpers --- src/datetime.rs | 84 +----------------------- src/macros.rs | 6 +- src/serde_helpers.rs | 153 +++++++++++++++++++++++-------------------- src/uuid.rs | 88 ++++++++++++------------- 4 files changed, 131 insertions(+), 200 deletions(-) diff --git a/src/datetime.rs b/src/datetime.rs index 4175c1a6..ec5ec667 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -10,11 +10,6 @@ use std::{ #[cfg(feature = "chrono-0_4")] use chrono::{LocalResult, TimeZone, Utc}; -#[cfg(all( - feature = "serde_with-3", - any(feature = "chrono-0_4", feature = "time-0_3", feature = "jiff-0_2") -))] -use serde::{Deserialize, Deserializer, Serialize}; use time::format_description::well_known::Rfc3339; pub use crate::datetime::builder::DateTimeBuilder; @@ -108,7 +103,7 @@ use crate::error::{Error, Result}; /// /// ### `serde_helpers` /// The `bson` crate provides a number of useful helpers for serializing and deserializing -/// various datetime types to and from different formats using the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/) +/// various datetime types to and from different formats using the [`serde_with`](https://docs.rs/serde_with/latest/serde_with/) /// crate. /// /// > **Note:** All helpers in this module require use of the [`#[serde_as]`](https://docs.rs/serde_with/latest/serde_with/attr.serde_as.html) @@ -149,7 +144,7 @@ use crate::error::{Error, Result}; /// } /// # } /// ``` -/// The main benefit of using the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/) crate +/// The main benefit of using the [`serde_with`](https://docs.rs/serde_with/latest/serde_with/) crate /// is that it can handle nested [`chrono::DateTime`] values (e.g. in [`Option`] or [`Vec`]). /// ``` /// # #[cfg(all(feature = "chrono-0_4", feature = "serde_with-3"))] @@ -496,31 +491,6 @@ impl From> for crate::DateTime { } } -#[cfg(all(feature = "chrono-0_4", feature = "serde_with-3"))] -impl<'de> serde_with::DeserializeAs<'de, chrono::DateTime> for crate::DateTime { - fn deserialize_as(deserializer: D) -> std::result::Result, D::Error> - where - D: Deserializer<'de>, - { - let dt = DateTime::deserialize(deserializer)?; - Ok(dt.to_chrono()) - } -} - -#[cfg(all(feature = "chrono-0_4", feature = "serde_with-3"))] -impl serde_with::SerializeAs> for crate::DateTime { - fn serialize_as( - source: &chrono::DateTime, - serializer: S, - ) -> std::result::Result - where - S: serde::Serializer, - { - let dt = DateTime::from_chrono(*source); - dt.serialize(serializer) - } -} - #[cfg(feature = "jiff-0_2")] impl From for jiff::Timestamp { fn from(bson_dt: DateTime) -> Self { @@ -535,31 +505,6 @@ impl From for crate::DateTime { } } -#[cfg(all(feature = "jiff-0_2", feature = "serde_with-3"))] -impl<'de> serde_with::DeserializeAs<'de, jiff::Timestamp> for crate::DateTime { - fn deserialize_as(deserializer: D) -> std::result::Result - where - D: Deserializer<'de>, - { - let dt = DateTime::deserialize(deserializer)?; - Ok(dt.to_jiff()) - } -} - -#[cfg(all(feature = "jiff-0_2", feature = "serde_with-3"))] -impl serde_with::SerializeAs for crate::DateTime { - fn serialize_as( - source: &jiff::Timestamp, - serializer: S, - ) -> std::result::Result - where - S: serde::Serializer, - { - let dt = DateTime::from_jiff(*source); - dt.serialize(serializer) - } -} - #[cfg(feature = "time-0_3")] impl From for time::OffsetDateTime { fn from(bson_dt: DateTime) -> Self { @@ -573,28 +518,3 @@ impl From for crate::DateTime { Self::from_time_0_3(x) } } - -#[cfg(all(feature = "time-0_3", feature = "serde_with-3"))] -impl<'de> serde_with::DeserializeAs<'de, time::OffsetDateTime> for crate::DateTime { - fn deserialize_as(deserializer: D) -> std::result::Result - where - D: Deserializer<'de>, - { - let dt = DateTime::deserialize(deserializer)?; - Ok(dt.to_time_0_3()) - } -} - -#[cfg(all(feature = "time-0_3", feature = "serde_with-3"))] -impl serde_with::SerializeAs for crate::DateTime { - fn serialize_as( - source: &time::OffsetDateTime, - serializer: S, - ) -> std::result::Result - where - S: serde::Serializer, - { - let dt = DateTime::from_time_0_3(*source); - dt.serialize(serializer) - } -} diff --git a/src/macros.rs b/src/macros.rs index b0fd3993..861268ec 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -470,7 +470,8 @@ macro_rules! serde_conv_doc { } } - impl SerializeAs<$t> for $m { + #[cfg(feature = "serde_with-3")] + impl serde_with::SerializeAs<$t> for $m { fn serialize_as(x: &$t, serializer: S) -> Result where S: Serializer, @@ -479,7 +480,8 @@ macro_rules! serde_conv_doc { } } - impl<'de> DeserializeAs<'de, $t> for $m { + #[cfg(feature = "serde_with-3")] + impl<'de> serde_with::DeserializeAs<'de, $t> for $m { fn deserialize_as(deserializer: D) -> Result<$t, D::Error> where D: Deserializer<'de>, diff --git a/src/serde_helpers.rs b/src/serde_helpers.rs index 79b0620e..4f7d9323 100644 --- a/src/serde_helpers.rs +++ b/src/serde_helpers.rs @@ -1,4 +1,51 @@ -//! Collection of helper functions for serializing to and deserializing from BSON using Serde +//! Collection of helper functions for serializing to and deserializing from BSON using Serde. +//! +//! The submodules here provide converter types that can be used with the `#[serde(with = ...)]` +//! annotation. These modules follow a naming convention: +//! * _module name_ - the _base type_ to be converted +//! * _module_`::AsFoo` - when serializing/deserializing a field of the base type, store it as a +//! _Foo_ value +//! * _module_`::FromFoo` - when serializing/deserializing a field of type _Foo_, store it as a +//! value of the base type +//! +//! For example, the [`object_id`] module provides both [`object_id::AsHexString`] and +//! [`object_id::FromHexString`]: +//! ``` +//! # use serde::{Deserialize, Serialize}; +//! use bson::{doc, serde_helpers::object_id, oid::ObjectId}; +//! +//! #[derive(Deserialize, Serialize)] +//! struct Example { +//! // No conversions applied; will serialize as the BSON value. +//! basic: ObjectId, +//! // In code, an ObjectId; when serialized, a hex string. +//! #[serde(with = "object_id::AsHexString")] +//! as_hex: ObjectId, +//! // In code, a hex string; serializes as a BSON objectid. +//! #[serde(with = "object_id::FromHexString")] +//! from_hex: String, +//! } +//! ``` +//! +//! If the `serde_with-3` feature is enabled, these converters can also be used with the +//! `#[serde_as(as = ...)]` annotation, which provides similar conversion functionality with the +//! added flexibility of handling many container types automatically: +//! ``` +//! # #[cfg(feature = "serde_with-3")] +//! # { +//! # use serde::{Deserialize, Serialize}; +//! use bson::{doc, serde_helpers::object_id, oid::ObjectId}; +//! +//! #[serde_with::serde_as] +//! #[derive(Deserialize, Serialize)] +//! struct Example { +//! #[serde_as(as = "Option")] +//! optional: Option, +//! } +//! # } +//! ``` +//! See the crate documentation for [`serde_with`](https://docs.rs/serde_with/latest/serde_with/) for more details. + use serde::{de::Visitor, Deserialize, Serialize}; use std::{ marker::PhantomData, @@ -6,17 +53,14 @@ use std::{ result::Result, }; -/// Type converters for serializing and deserializing [`crate::oid::ObjectId`] using -/// [`serde_with::serde_as`]. +/// Type converters for serializing and deserializing [`crate::oid::ObjectId`]. /// /// ## Available converters /// - [`object_id::AsHexString`] — converts an [`crate::oid::ObjectId`] to and from a hex string. /// - [`object_id::FromHexString`] — converts a hex string to and from an [`crate::oid::ObjectId`]. -#[cfg(feature = "serde_with-3")] pub mod object_id { use crate::{macros::serde_conv_doc, oid::ObjectId}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; - use serde_with::{DeserializeAs, SerializeAs}; serde_conv_doc!( /// Converts an [`ObjectId`] to and from a hex string. @@ -71,8 +115,7 @@ pub mod object_id { ); } -/// Type converters for serializing and deserializing [`crate::DateTime`] using -/// [`serde_with::serde_as`]. +/// Type converters for serializing and deserializing [`crate::DateTime`]. /// /// ## Available converters /// - [`datetime::AsRfc3339String`] — converts a [`crate::DateTime`] to and from an RFC 3339 string. @@ -85,12 +128,10 @@ pub mod object_id { /// [`crate::DateTime`]. /// - [`datetime::FromTime03OffsetDateTime`] — converts a [`time::OffsetDateTime`] to and from a /// [`crate::DateTime`]. -#[cfg(feature = "serde_with-3")] pub mod datetime { use crate::{macros::serde_conv_doc, DateTime}; use chrono::Utc; use serde::{Deserialize, Deserializer, Serialize, Serializer}; - use serde_with::{DeserializeAs, SerializeAs}; serde_conv_doc!( /// Converts a [`DateTime`] to and from an RFC 3339 (ISO 8601) formatted string. @@ -257,17 +298,14 @@ pub mod datetime { ); } -/// Type converters for serializing and deserializing `crate::Timestamp` using -/// [`serde_with::serde_as`]. +/// Type converters for serializing and deserializing `crate::Timestamp`. /// /// ## Available converters /// - [`timestamp::AsU32`] — converts a [`crate::Timestamp`] to and from a `u32`. /// - [`timestamp::FromU32`] — converts a `u32` to and from a [`crate::Timestamp`]. -#[cfg(feature = "serde_with-3")] pub mod timestamp { use crate::{macros::serde_conv_doc, Timestamp}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; - use serde_with::{DeserializeAs, SerializeAs}; serde_conv_doc!( /// Converts a [`Timestamp`] to and from a `u32`. @@ -336,7 +374,7 @@ pub mod timestamp { ); } -/// Type converters for serializing and deserializing `u32` using [`serde_with::serde_as`]. +/// Type converters for serializing and deserializing `u32`. /// /// ## Available converters /// - [`u32::AsF64`] — converts a `u32` to and from an `f64`. @@ -346,7 +384,6 @@ pub mod timestamp { pub mod u32 { use crate::macros::serde_conv_doc; use serde::{Deserialize, Deserializer, Serialize, Serializer}; - use serde_with::{DeserializeAs, SerializeAs}; serde_conv_doc!( /// Converts a `u32` to and from an `f64`. @@ -443,11 +480,9 @@ pub mod u32 { /// - [`u64::AsF64`] — converts a `u64` to and from an `f64`. /// - [`u64::AsI32`] — converts a `u64` to and from an `i32`. /// - [`u64::AsI64`] — converts a `u64` to and from an `i64`. -#[cfg(feature = "serde_with-3")] pub mod u64 { use crate::macros::serde_conv_doc; use serde::{Deserialize, Deserializer, Serialize, Serializer}; - use serde_with::{DeserializeAs, SerializeAs}; serde_conv_doc!( /// Converts a `u64` to and from an `f64`. @@ -543,10 +578,10 @@ pub mod u64 { ); } -/// Type converters for serializing and deserializing [`uuid::Uuid`] using -/// [`serde_with::serde_as`]. +/// Type converters for serializing and deserializing [`uuid::Uuid`]. /// /// ## Available converters +/// - [`uuid_1::FromBson`] - serializes a [`crate::Uuid`] as a [`uuid::Uuid`]. /// - [`uuid_1::AsBinary`] — serializes a [`uuid::Uuid`] as a [`crate::Binary`]. /// - [`uuid_1::AsCSharpLegacyBinary`] — serializes a [`uuid::Uuid`] as a [`crate::Binary`] in the /// legacy C# driver UUID format. @@ -554,13 +589,38 @@ pub mod u64 { /// legacy Java driver UUID format. /// - [`uuid_1::AsPythonLegacyBinary`] — serializes a [`uuid::Uuid`] as a [`crate::Binary`] in the /// legacy Python driver UUID format. -#[cfg(all(feature = "serde_with-3", feature = "uuid-1"))] +#[cfg(feature = "uuid-1")] pub mod uuid_1 { use crate::macros::serde_conv_doc; use serde::{Deserialize, Deserializer, Serialize, Serializer}; - use serde_with::{DeserializeAs, SerializeAs}; use uuid::Uuid; + serde_conv_doc!( + /// Converts a ['crate::Uuid`] to and from a [`uuid::Uuid`]. + /// ``` + /// # #[cfg(all(feature = "uuid-1", feature = "serde_with-3"))] + /// # { + /// use bson::serde_helpers::uuid_1; + /// use serde::{Serialize, Deserialize}; + /// use serde_with::serde_as; + /// #[serde_as] + /// #[derive(Serialize, Deserialize)] + /// struct Item { + /// #[serde_as(as = "uuid_1::FromBson")] + /// pub id: bson::Uuid, + /// } + /// # } + /// ``` + pub FromBson, + crate::Uuid, + |bson_uuid: &crate::Uuid| -> Result { + Ok((*bson_uuid).into()) + }, + |uuid: Uuid| -> Result { + Ok(crate::Uuid::from(uuid)) + } + ); + serde_conv_doc!( /// Serializes a [`Uuid`] as a [`crate::Binary`] and deserializes a [`Uuid`] from a [`crate::Binary`]. /// ```rust @@ -694,57 +754,6 @@ pub mod uuid_1 { ); } -#[allow(unused_macros)] -macro_rules! as_binary_mod { - ($feat:meta, $uu:path) => { - use serde::{Deserialize, Deserializer, Serialize, Serializer}; - use std::result::Result; - use $uu; - - /// Serializes a Uuid as a Binary. - pub fn serialize(val: &Uuid, serializer: S) -> Result { - crate::uuid::Uuid::from(*val).serialize(serializer) - } - - /// Deserializes a Uuid from a Binary. - pub fn deserialize<'de, D>(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let bson_uuid = crate::uuid::Uuid::deserialize(deserializer)?; - Ok(bson_uuid.into()) - } - }; -} - -#[allow(unused_macros)] -macro_rules! as_legacy_binary_mod { - ($feat:meta, $uu:path, $rep:path) => { - use crate::{uuid::UuidRepresentation, Binary}; - use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; - use std::result::Result; - use $uu; - - /// Serializes a Uuid as a Binary in the legacy UUID format. - pub fn serialize(val: &Uuid, serializer: S) -> Result { - let binary = Binary::from_uuid_with_representation(crate::uuid::Uuid::from(*val), $rep); - binary.serialize(serializer) - } - - /// Deserializes a Uuid from a Binary in the legacy UUID format. - pub fn deserialize<'de, D>(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - let binary = Binary::deserialize(deserializer)?; - let uuid = binary - .to_uuid_with_representation($rep) - .map_err(de::Error::custom)?; - Ok(uuid.into()) - } - }; -} - /// Wrapping a type in `HumanReadable` signals to the BSON serde integration that it and all /// recursively contained types should be serialized to and deserialized from their human-readable /// formats. diff --git a/src/uuid.rs b/src/uuid.rs index dcf0cbff..29825ef6 100644 --- a/src/uuid.rs +++ b/src/uuid.rs @@ -74,25 +74,55 @@ //! # }; //! ``` //! +//! ## Serde conversion +//! +//! Fields using the [`uuid::Uuid`] type can be (de)serialized as BSON using the converters provided +//! in [`serde_helpers`](crate::serde_helpers): +//! +//! ``` +//! # #[cfg(feature = "uuid-1")] +//! # { +//! use uuid; +//! use serde::{Deserialize, Serialize}; +//! use bson::{doc, serde_helpers::uuid_1}; +//! #[derive(Deserialize, Serialize, PartialEq, Debug)] +//! struct Foo { +//! /// Serializes as a BSON binary rather than using [`uuid::Uuid`]'s serialization +//! #[serde(with = "uuid_1::AsBinary")] +//! as_bson: uuid::Uuid, +//! } +//! +//! let foo = Foo { +//! as_bson: uuid::Uuid::new_v4(), +//! }; +//! +//! let expected = doc! { +//! "as_bson": bson::Uuid::from(foo.as_bson), +//! }; +//! +//! assert_eq!(bson::serialize_to_document(&foo)?, expected); +//! # } +//! # Ok::<(), Box>(()) +//! ``` +//! //! ## The `serde_with-3` feature flag //! //! The `serde_with-3` feature can be enabled to support more ergonomic serde attributes for -//! (de)serializing [`uuid::Uuid`] from/to BSON via the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/) -//! crate. The main benefit of this compared to the regular `serde_helpers` is that `serde_with-3` -//! can handle nested [`uuid::Uuid`] values (e.g. in [`Option`]), whereas the former only works on -//! fields that are exactly [`uuid::Uuid`]. +//! conversions. The main benefit of this compared to the regular `serde_helpers` is that +//! `serde_with-3` can handle nested [`uuid::Uuid`] values (e.g. in [`Option`]), whereas the former +//! only works on fields that are exactly [`uuid::Uuid`]. //! ``` //! # #[cfg(all(feature = "uuid-1", feature = "serde_with-3"))] //! # { -//! # use uuid as uuid; +//! # use uuid; //! use serde::{Deserialize, Serialize}; -//! use bson::doc; +//! use bson::{doc, serde_helpers::uuid_1}; //! //! #[serde_with::serde_as] //! #[derive(Deserialize, Serialize, PartialEq, Debug)] //! struct Foo { //! /// Serializes as a BSON binary rather than using [`uuid::Uuid`]'s serialization -//! #[serde_as(as = "Option")] +//! #[serde_as(as = "Option")] //! as_bson: Option, //! } //! @@ -113,7 +143,6 @@ //! //! [`crate::Uuid`]'s `serde` implementation is the same as [`uuid::Uuid`]'s //! for non-BSON formats such as JSON: -//! //! ``` rust //! # #[cfg(feature = "uuid-1")] //! # { @@ -453,41 +482,12 @@ impl Binary { } } -macro_rules! trait_impls { - ($feat:meta, $u:ty) => { - #[cfg($feat)] - impl From<$u> for Binary { - fn from(uuid: $u) -> Self { - Binary { - subtype: BinarySubtype::Uuid, - bytes: uuid.as_bytes().to_vec(), - } - } - } - - #[cfg(all($feat, feature = "serde_with-3"))] - impl<'de> serde_with::DeserializeAs<'de, $u> for crate::Uuid { - fn deserialize_as(deserializer: D) -> std::result::Result<$u, D::Error> - where - D: serde::Deserializer<'de>, - { - use serde::Deserialize as _; - let uuid = Uuid::deserialize(deserializer)?; - Ok(uuid.into()) - } - } - - #[cfg(all($feat, feature = "serde_with-3"))] - impl serde_with::SerializeAs<$u> for crate::Uuid { - fn serialize_as(source: &$u, serializer: S) -> std::result::Result - where - S: serde::Serializer, - { - use serde::Serialize as _; - let uuid = Uuid::from(*source); - uuid.serialize(serializer) - } +#[cfg(feature = "uuid-1")] +impl From for Binary { + fn from(uuid: uuid::Uuid) -> Self { + Binary { + subtype: BinarySubtype::Uuid, + bytes: uuid.as_bytes().to_vec(), } - }; + } } -trait_impls!(feature = "uuid-1", uuid::Uuid); From 7537a0eff14f82837edb2c82c8919a312652edd7 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Tue, 19 Aug 2025 13:38:09 +0100 Subject: [PATCH 2/4] fix serde-tests --- serde-tests/test.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/serde-tests/test.rs b/serde-tests/test.rs index 44a6697d..95d17186 100644 --- a/serde-tests/test.rs +++ b/serde-tests/test.rs @@ -1187,13 +1187,14 @@ fn u2i() { #[test] fn serde_with_chrono() { + use bson::serde_helpers::datetime; #[serde_with::serde_as] #[derive(Deserialize, Serialize, PartialEq, Debug)] struct Foo { - #[serde_as(as = "Option")] + #[serde_as(as = "Option")] as_bson: Option>, - #[serde_as(as = "Option")] + #[serde_as(as = "Option")] none_bson: Option>, } @@ -1211,13 +1212,14 @@ fn serde_with_chrono() { #[test] fn serde_with_uuid() { + use bson::serde_helpers::uuid_1; #[serde_with::serde_as] #[derive(Deserialize, Serialize, PartialEq, Debug)] struct Foo { - #[serde_as(as = "Option")] + #[serde_as(as = "Option")] as_bson: Option, - #[serde_as(as = "Option")] + #[serde_as(as = "Option")] none_bson: Option, } From 01573df67f73ccf64af9544a985b5126cc30ba50 Mon Sep 17 00:00:00 2001 From: Abraham Egnor Date: Tue, 19 Aug 2025 13:45:39 +0100 Subject: [PATCH 3/4] more fixes --- src/macros.rs | 4 ++-- src/serde_helpers.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index 861268ec..6eadf152 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -439,7 +439,7 @@ macro_rules! rawdoc { /// /// This macro generates a `SerializeAs`/`DeserializeAs` implementation for a given type, /// with optional struct-level attributes like `#[derive(...)]` or `/// doc comments`. -#[allow(unused_macros)] +#[cfg(feature = "serde")] macro_rules! serde_conv_doc { ($(#[$meta:meta])* $vis:vis $m:ident, $t:ty, $ser:expr, $de:expr) => { #[allow(non_camel_case_types)] @@ -493,5 +493,5 @@ macro_rules! serde_conv_doc { }; } -#[allow(unused_imports)] +#[cfg(feature = "serde")] pub(crate) use serde_conv_doc; diff --git a/src/serde_helpers.rs b/src/serde_helpers.rs index 4f7d9323..b100ba55 100644 --- a/src/serde_helpers.rs +++ b/src/serde_helpers.rs @@ -130,6 +130,7 @@ pub mod object_id { /// [`crate::DateTime`]. pub mod datetime { use crate::{macros::serde_conv_doc, DateTime}; + #[cfg(feature = "chrono-0_4")] use chrono::Utc; use serde::{Deserialize, Deserializer, Serialize, Serializer}; From 7b3ebec9f17a8315fe7796563cc375e48669e2c9 Mon Sep 17 00:00:00 2001 From: Isabel Atkinson Date: Tue, 19 Aug 2025 14:41:09 -0600 Subject: [PATCH 4/4] additional improvements --- README.md | 2 +- src/lib.rs | 2 +- src/serde_helpers.rs | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4faf91c2..a7419660 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Note that if you are using `bson` through the `mongodb` crate, you do not need t | `chrono-0_4` | Enable support for v0.4 of the [`chrono`](https://docs.rs/chrono/0.4) crate in the public API. | n/a | no | | `uuid-1` | Enable support for v1.x of the [`uuid`](https://docs.rs/uuid/1.0) crate in the public API. | n/a | no | | `time-0_3` | Enable support for v0.3 of the [`time`](https://docs.rs/time/0.3) crate in the public API. | n/a | no | -| `serde_with-3` | Enable [`serde_with`](https://docs.rs/serde_with/3.x) 3.x integrations for `bson::DateTime` and `bson::Uuid`.| `serde_with` | no | +| `serde_with-3` | Enable [`serde_with`](https://docs.rs/serde_with/3.x) type conversion utilities in the public API. | `serde_with` | no | | `serde_path_to_error` | Enable support for error paths via integration with [`serde_path_to_error`](https://docs.rs/serde_path_to_err/latest). This is an unstable feature and any breaking changes to `serde_path_to_error` may affect usage of it via this feature. | `serde_path_to_error` | no | | `compat-3-0-0` | Required for future compatibility if default features are disabled. | n/a | no | | `large_dates` | Increase the supported year range for some `bson::DateTime` utilities from +/-9,999 (inclusive) to +/-999,999 (inclusive). Note that enabling this feature can impact performance and introduce parsing ambiguities. | n/a | no | diff --git a/src/lib.rs b/src/lib.rs index 43cfba1e..071180d8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -66,7 +66,7 @@ //! | `uuid-1` | Enable support for v1.x of the [`uuid`](https://docs.rs/uuid/1.x) crate in the public API. | no | //! | `time-0_3` | Enable support for v0.3 of the [`time`](https://docs.rs/time/0.3) crate in the public API. | no | //! | `serde` | Enable integration with the [`serde`](https://docs.rs/serde/) serialization/deserialization framework. | no | -//! | `serde_with-3` | Enable [`serde_with`](https://docs.rs/serde_with/3.x) 3.x integrations for [`DateTime`] and [`Uuid`]. | no | +//! | `serde_with-3` | Enable [`serde_with`](https://docs.rs/serde_with/3.x) type conversion utilities in the public API. | no | //! | `serde_path_to_error` | Enable support for error paths via integration with [`serde_path_to_error`](https://docs.rs/serde_path_to_err/latest). This is an unstable feature and any breaking changes to `serde_path_to_error` may affect usage of it via this feature. | no | //! | `compat-3-0-0` | Required for future compatibility if default features are disabled. | yes | //! | `large_dates` | Increase the supported year range for some `bson::DateTime` utilities from +/-9,999 (inclusive) to +/-999,999 (inclusive). Note that enabling this feature can impact performance and introduce parsing ambiguities. | no | diff --git a/src/serde_helpers.rs b/src/serde_helpers.rs index b100ba55..26b59b27 100644 --- a/src/serde_helpers.rs +++ b/src/serde_helpers.rs @@ -299,7 +299,7 @@ pub mod datetime { ); } -/// Type converters for serializing and deserializing `crate::Timestamp`. +/// Type converters for serializing and deserializing [`crate::Timestamp`]. /// /// ## Available converters /// - [`timestamp::AsU32`] — converts a [`crate::Timestamp`] to and from a `u32`. @@ -381,7 +381,6 @@ pub mod timestamp { /// - [`u32::AsF64`] — converts a `u32` to and from an `f64`. /// - [`u32::AsI32`] — converts a `u32` to and from an `i32`. /// - [`u32::AsI64`] — converts a `u32` to and from an `i64`. -#[cfg(feature = "serde_with-3")] pub mod u32 { use crate::macros::serde_conv_doc; use serde::{Deserialize, Deserializer, Serialize, Serializer}; @@ -475,7 +474,7 @@ pub mod u32 { ); } -/// Type converters for serializing and deserializing `u64` using [`serde_with::serde_as`]. +/// Type converters for serializing and deserializing `u64`. /// /// ## Available converters /// - [`u64::AsF64`] — converts a `u64` to and from an `f64`. @@ -597,7 +596,7 @@ pub mod uuid_1 { use uuid::Uuid; serde_conv_doc!( - /// Converts a ['crate::Uuid`] to and from a [`uuid::Uuid`]. + /// Converts a [`crate::Uuid`] to and from a [`uuid::Uuid`]. /// ``` /// # #[cfg(all(feature = "uuid-1", feature = "serde_with-3"))] /// # {