Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a51f29e
Refactor OffsetDateTime and i64 to DateTime helpers to use serde_conv
JamieTsai1024 Jul 8, 2025
194177a
RUST-1992 Updates to allow the driver to be updated (#571)
abr-egn Jul 9, 2025
03e9a51
Refactor type converters betweem timestamp and u32 with serde_conv
JamieTsai1024 Jul 9, 2025
f1577fd
Refactor u32 and u64 to f64 converters to use serde_conv
JamieTsai1024 Jul 9, 2025
b8ad904
Rename u32 module to timestamp
JamieTsai1024 Jul 9, 2025
a1ad2de
Clean up remaining u32_as_timestamp converter
JamieTsai1024 Jul 9, 2025
5529ec8
Fix struct capitalization
JamieTsai1024 Jul 10, 2025
a7c182a
Refactor unsigned (u32, u64) to signed (i32, i64) converters using se…
JamieTsai1024 Jul 10, 2025
693faa8
Consolidate module names under u32 and u64
JamieTsai1024 Jul 10, 2025
a9873d3
Consolidate module names under u32 and u64
JamieTsai1024 Jul 10, 2025
b9b08cf
Refactor uuid to binary converter to use serde_conv
JamieTsai1024 Jul 11, 2025
1ccea32
Reorder tests based on serde_helpers ordering
JamieTsai1024 Jul 11, 2025
1db7343
Refactor uuid to legacy binary converters using serde_conv
JamieTsai1024 Jul 11, 2025
174fe65
RUST-2240 Move `serde_json` API behind a feature flag (#567)
isabelatkinson Jul 14, 2025
7077c0b
Rename bson_datetime module to datetime
JamieTsai1024 Jul 14, 2025
e6b69c5
Merge branch 'RUST-1748-serde_conv-2' into RUST-1748-serde_conv-3
JamieTsai1024 Jul 14, 2025
e1e4dae
Merge branch 2 into branch 3
JamieTsai1024 Jul 14, 2025
ae2b0a4
Fix rustdoc imports
JamieTsai1024 Jul 14, 2025
c14f554
Merge branch 'RUST-1748-serde_conv-2' into RUST-1748-serde_conv-3
JamieTsai1024 Jul 14, 2025
f834214
Add back deleted u32 tests from merge
JamieTsai1024 Jul 14, 2025
ec82af4
Fix datetime rustdoc comments from merge
JamieTsai1024 Jul 14, 2025
47cbddd
Update rustdoc comments
JamieTsai1024 Jul 14, 2025
b85d7d0
Merge branch 'RUST-1748-serde_conv-2' into RUST-1748-serde_conv-3
JamieTsai1024 Jul 14, 2025
53090e9
Revert all UUID changes (separate to another PR)
JamieTsai1024 Jul 14, 2025
f0c3833
Fix rustdoc import
JamieTsai1024 Jul 14, 2025
00a4f9c
Copy documentation and test changes for ObjectId
JamieTsai1024 Jul 14, 2025
3103c27
Try uncommenting conditional compilation on rustdoc comments
JamieTsai1024 Jul 15, 2025
6f74ead
Undo uncommenting rustdocs
JamieTsai1024 Jul 15, 2025
f81dfd2
Revert all ObjectId changes (separate to another PR)
JamieTsai1024 Jul 15, 2025
60b6c4f
Move #[cfg(feature = serde_with-3)] attribute to test function
JamieTsai1024 Jul 15, 2025
d91ba76
Break tests into smaller functions
JamieTsai1024 Jul 15, 2025
de0b400
Remove whitespace diffs
JamieTsai1024 Jul 15, 2025
844b50c
Merge branch 'RUST-1748-serde_conv-2' into RUST-1748-serde_conv-3
JamieTsai1024 Jul 15, 2025
1e9903a
Fix rustdocs whitespace
JamieTsai1024 Jul 15, 2025
9169665
Remove whitespace
JamieTsai1024 Jul 15, 2025
9938011
Remove Result imports
JamieTsai1024 Jul 15, 2025
7e8c859
RUST-2057 Test relaxed encoding of y10k dates (#572)
abr-egn Jul 16, 2025
f14d6d1
RUST-1748 Refactor BSON DateTime serde converters using serde_conv_do…
JamieTsai1024 Jul 16, 2025
31a23d6
Merge branch 'RUST-1748-serde_conv-2' into RUST-1748-serde_conv-3
JamieTsai1024 Jul 16, 2025
648bfaa
Merge branch 'main' into RUST-1748-serde_conv-3
JamieTsai1024 Jul 16, 2025
59bf3fa
Merge main
JamieTsai1024 Jul 16, 2025
65d935a
Merge branch 'RUST-1748-serde_conv-3' of https://github.com/JamieTsai…
JamieTsai1024 Jul 16, 2025
dd78cf6
Fix merge from main
JamieTsai1024 Jul 16, 2025
103011c
Reorder structs and tests
JamieTsai1024 Jul 16, 2025
19329dd
Revert last 6 commits
JamieTsai1024 Jul 17, 2025
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
36 changes: 17 additions & 19 deletions src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,16 @@ 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/)
/// 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)
/// > attribute on the struct. This enables the enhanced serialization behavior provided by
/// > `serde_with-3`.
///
/// For example, to serialize a [`chrono::DateTime`] as a BSON datetime, you can use
/// various datetime types to and from different formats. For example, to serialize a
/// [`chrono::DateTime`] as a BSON datetime, you can use
/// [`crate::serde_helpers::datetime::FromChrono04DateTime`].
/// Similarly, to serialize a BSON [`DateTime`] to a string, you can use
/// [`crate::serde_helpers::datetime::AsRfc3339String`]. Check out the
/// [`crate::serde_helpers`] module documentation for a list of all of the helpers
/// offered by the crate.
/// [`crate::serde_helpers`] module documentation for a list of all of the helpers offered by the
/// crate.
///
/// ```rust
/// # #[cfg(all(feature = "chrono-0_4", feature = "serde_with-3"))]
/// # #[cfg(feature = "chrono-0_4")]
/// # {
/// use serde::{Serialize, Deserialize};
/// use serde_with::serde_as;
Expand All @@ -143,26 +138,29 @@ use crate::error::{Error, Result};
/// chrono_as_bson: chrono::DateTime<chrono::Utc>,
///
/// // serializes as an RFC 3339 / ISO-8601 string.
/// // this requires the "serde_with-3" feature flag
/// #[serde_as(as = "datetime::AsRfc3339String")]
/// bson_as_string: bson::DateTime,
/// }
/// # }
/// ```
/// The main benefit of using the [`serde_with`](https://docs.rs/serde_with/1.11.0/serde_with/) crate
/// is that it can handle nested [`chrono::DateTime`] values (e.g. in [`Option`] or [`Vec`]).
/// ### The `serde_with-3` feature flag
///
/// The `serde_with-3` feature can be enabled to support more ergonomic serde attributes for
/// (de)serializing [`chrono::DateTime`] 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 [`chrono::DateTime`] values (e.g. in [`Option`]), whereas the former only
/// works on fields that are exactly [`chrono::DateTime`].
/// ```
/// # #[cfg(all(feature = "chrono-0_4", feature = "serde_with-3"))]
/// # {
/// use serde::{Deserialize, Serialize};
/// use serde_with::serde_as;
/// use bson::{doc, serde_helpers::datetime};
/// use bson::doc;
///
/// #[serde_as]
/// #[serde_with::serde_as]
/// #[derive(Deserialize, Serialize, PartialEq, Debug)]
/// struct Foo {
/// /// serializes as a BSON datetime rather than using [`chrono::DateTime`]'s serialization
/// #[serde_as(as = "Option<datetime::FromChrono04DateTime>")]
/// /// Serializes as a BSON datetime rather than using [`chrono::DateTime`]'s serialization
/// #[serde_as(as = "Option<bson::DateTime>")]
/// as_bson: Option<chrono::DateTime<chrono::Utc>>,
/// }
///
Expand Down
7 changes: 5 additions & 2 deletions src/extjson/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ use serde::{
Deserialize,
Serialize,
};
use serde_with::serde_as;
use std::borrow::Cow;

use crate::{
base64,
error::{Error, Result},
oid,
raw::serde::CowStr,
serde_helpers::u32,
spec::BinarySubtype,
Bson,
};
Expand Down Expand Up @@ -215,12 +217,13 @@ pub(crate) struct Timestamp {
}

#[derive(Serialize, Deserialize, Debug)]
#[serde_as]
#[serde(deny_unknown_fields)]
pub(crate) struct TimestampBody {
#[serde(serialize_with = "crate::serde_helpers::serialize_u32_as_i64")]
#[serde_as(as = "u32::AsI64")]
pub(crate) t: u32,

#[serde(serialize_with = "crate::serde_helpers::serialize_u32_as_i64")]
#[serde_as(as = "u32::AsI64")]
pub(crate) i: u32,
}

Expand Down
Loading