@@ -108,20 +108,25 @@ use crate::error::{Error, Result};
108108///
109109/// ### `serde_helpers`
110110/// The `bson` crate provides a number of useful helpers for serializing and deserializing
111- /// various datetime types to and from different formats. For example, to serialize a
112- /// [`chrono::DateTime`] as a BSON datetime, you can use
113- /// [`crate::serde_helpers::bson_datetime::FromChronoDateTime`].
114- /// Similarly, to serialize a BSON [`DateTime`] to a string, you can use
115- /// [`crate::serde_helpers::bson_datetime::AsRfc3339String`]. Check out the
116- /// [`crate::serde_helpers`] module documentation for a list of all of the helpers offered by the
111+ /// various datetime types to and from different formats using the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/)
117112/// crate.
118113///
114+ /// > **Note:** All helpers in this module require use of the [`#[serde_as]`](https://docs.rs/serde_with/latest/serde_with/attr.serde_as.html)
115+ /// > attribute on the struct. This enables the enhanced serialization behavior provided by
116+ /// > `serde_with-3`.
117+ ///
118+ /// For example, to serialize a [`chrono::DateTime`] as a BSON datetime, you can use
119+ /// [`crate::serde_helpers::datetime::FromChrono04DateTime`].
120+ /// Similarly, to serialize a BSON [`DateTime`] to a string, you can use
121+ /// [`crate::serde_helpers::datetime::AsRfc3339String`]. Check out the
122+ /// [`crate::serde_helpers`] module documentation for a list of all of the helpers
123+ /// offered by the crate.
119124/// ```rust
120- /// # #[cfg(feature = "chrono-0_4")]
125+ /// # #[cfg(all( feature = "chrono-0_4", feature = "serde_with-3") )]
121126/// # {
122127/// use serde::{Serialize, Deserialize};
123128/// use serde_with::serde_as;
124- /// use bson::serde_helpers::bson_datetime ;
129+ /// use bson::serde_helpers::datetime ;
125130///
126131/// #[serde_as]
127132/// #[derive(Serialize, Deserialize)]
@@ -134,33 +139,30 @@ use crate::error::{Error, Result};
134139///
135140/// // serializes as a BSON datetime.
136141/// // this requires the "chrono-0_4" feature flag
137- /// #[serde_as(as = "bson_datetime::FromChronoDateTime ")]
142+ /// #[serde_as(as = "datetime::FromChrono04DateTime ")]
138143/// chrono_as_bson: chrono::DateTime<chrono::Utc>,
139144///
140145/// // serializes as an RFC 3339 / ISO-8601 string.
141- /// #[serde_as(as = "bson_datetime::AsRfc3339String")]
146+ /// // this requires the "serde_with-3" feature flag
147+ /// #[serde_as(as = "datetime::AsRfc3339String")]
142148/// bson_as_string: bson::DateTime,
143149/// }
144150/// # }
145151/// ```
146- /// ### The `serde_with-3` feature flag
147- ///
148- /// The `serde_with-3` feature can be enabled to support more ergonomic serde attributes for
149- /// (de)serializing [`chrono::DateTime`] from/to BSON via the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/)
150- /// crate. The main benefit of this compared to the regular `serde_helpers` is that `serde_with-3`
151- /// can handle nested [`chrono::DateTime`] values (e.g. in [`Option`]), whereas the former only
152- /// works on fields that are exactly [`chrono::DateTime`].
152+ /// The main benefit of using the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/) crate
153+ /// is that it can handle nested [`chrono::DateTime`] values (e.g. in [`Option`] or [`Vec`]).
153154/// ```
154155/// # #[cfg(all(feature = "chrono-0_4", feature = "serde_with-3"))]
155156/// # {
156157/// use serde::{Deserialize, Serialize};
157- /// use bson::doc;
158+ /// use serde_with::serde_as;
159+ /// use bson::{doc, serde_helpers::datetime};
158160///
159- /// #[serde_with:: serde_as]
161+ /// #[serde_as]
160162/// #[derive(Deserialize, Serialize, PartialEq, Debug)]
161163/// struct Foo {
162- /// /// Serializes as a BSON datetime rather than using [`chrono::DateTime`]'s serialization
163- /// #[serde_as(as = "Option<bson::DateTime >")]
164+ /// /// serializes as a BSON datetime rather than using [`chrono::DateTime`]'s serialization
165+ /// #[serde_as(as = "Option<datetime::FromChrono04DateTime >")]
164166/// as_bson: Option<chrono::DateTime<chrono::Utc>>,
165167/// }
166168///
0 commit comments