Skip to content

Commit 6f79f72

Browse files
committed
Slightly improve serde documentation
1 parent 236b7ad commit 6f79f72

File tree

4 files changed

+28
-32
lines changed

4 files changed

+28
-32
lines changed

src/datetime/serde.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ pub struct MicroSecondsTimestampVisitor;
2323
#[derive(Debug)]
2424
pub struct MilliSecondsTimestampVisitor;
2525

26-
/// Serialize into an ISO 8601 formatted string.
26+
/// Serialize into an ISO 8601 formatted string, with a format similar to RFC 3339.
2727
///
28-
/// See [the `serde` module](./serde/index.html) for alternate
29-
/// serializations.
28+
/// See [the `serde` module](crate::serde) for alternate serializations.
3029
impl<Tz: TimeZone> ser::Serialize for DateTime<Tz> {
3130
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
3231
where
@@ -54,7 +53,7 @@ impl<'de> de::Visitor<'de> for DateTimeVisitor {
5453
type Value = DateTime<FixedOffset>;
5554

5655
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
57-
formatter.write_str("a formatted date and time string or a unix timestamp")
56+
formatter.write_str("an RFC 3339 formatted date and time string")
5857
}
5958

6059
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
@@ -65,13 +64,9 @@ impl<'de> de::Visitor<'de> for DateTimeVisitor {
6564
}
6665
}
6766

68-
/// Deserialize a value that optionally includes a timezone offset in its
69-
/// string representation
67+
/// Deserialize an RFC 3339 formatted string into a `DateTime<FixedOffset>`.
7068
///
71-
/// The value to be deserialized must be an rfc3339 string.
72-
///
73-
/// See [the `serde` module](./serde/index.html) for alternate
74-
/// deserialization formats.
69+
/// See [the `serde` module](crate::serde) for alternate deserialization formats.
7570
impl<'de> de::Deserialize<'de> for DateTime<FixedOffset> {
7671
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
7772
where
@@ -81,12 +76,11 @@ impl<'de> de::Deserialize<'de> for DateTime<FixedOffset> {
8176
}
8277
}
8378

84-
/// Deserialize into a UTC value
79+
/// Deserialize an RFC 3339 formatted string into a `DateTime<Utc>`.
8580
///
86-
/// The value to be deserialized must be an rfc3339 string.
81+
/// If the value contains an offset from UTC that is not zero, the value will be converted to UTC.
8782
///
88-
/// See [the `serde` module](./serde/index.html) for alternate
89-
/// deserialization formats.
83+
/// See [the `serde` module](crate::serde) for alternate deserialization formats.
9084
impl<'de> de::Deserialize<'de> for DateTime<Utc> {
9185
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
9286
where
@@ -96,13 +90,12 @@ impl<'de> de::Deserialize<'de> for DateTime<Utc> {
9690
}
9791
}
9892

99-
/// Deserialize a value that includes no timezone in its string
100-
/// representation
93+
/// Deserialize an RFC 3339 formatted string into a `DateTime<Local>`.
10194
///
102-
/// The value to be deserialized must be an rfc3339 string.
95+
/// The value will remain the same instant in UTC, but the offset will be recalculated to match
96+
/// that of the `Local` platform time zone.
10397
///
104-
/// See [the `serde` module](./serde/index.html) for alternate
105-
/// serialization formats.
98+
/// See [the `serde` module](crate::serde) for alternate deserialization formats.
10699
#[cfg(feature = "clock")]
107100
impl<'de> de::Deserialize<'de> for DateTime<Local> {
108101
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>

src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,19 @@ pub use naive::__BenchYearFlags;
616616

617617
/// Serialization/Deserialization with serde.
618618
///
619-
/// This module provides default implementations for `DateTime` using the [RFC 3339][1] format and various
620-
/// alternatives for use with serde's [`with` annotation][2].
619+
/// The [`DateTime`] type has default implementations for (de)serializing to/from the [RFC 3339]
620+
/// format. This module provides alternatives for serializing to timestamps.
621+
///
622+
/// The alternatives are for use with serde's [`with` annotation] combined with the module name.
623+
/// Alternatively the individual `serialize` and `deserialize` functions in each module can be used
624+
/// with serde's [`serialize_with`] and [`deserialize_with`] annotations.
621625
///
622626
/// *Available on crate feature 'serde' only.*
623627
///
624-
/// [1]: https://tools.ietf.org/html/rfc3339
625-
/// [2]: https://serde.rs/field-attrs.html#with
628+
/// [RFC 3339]: https://tools.ietf.org/html/rfc3339
629+
/// [`with` annotation]: https://serde.rs/field-attrs.html#with
630+
/// [`serialize_with`]: https://serde.rs/field-attrs.html#serialize_with
631+
/// [`deserialize_with`]: https://serde.rs/field-attrs.html#deserialize_with
626632
#[cfg(feature = "serde")]
627633
pub mod serde {
628634
use core::fmt;

src/naive/datetime/serde.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ use serde::{de, ser};
33

44
use super::NaiveDateTime;
55

6-
/// Serialize a `NaiveDateTime` as an RFC 3339 string
6+
/// Serialize a `NaiveDateTime` as an ISO 8601 string.
77
///
8-
/// See [the `serde` module](./serde/index.html) for alternate
9-
/// serialization formats.
8+
/// See [the `naive::serde` module](crate::naive::serde) for alternate serialization formats.
109
impl ser::Serialize for NaiveDateTime {
1110
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1211
where

src/naive/mod.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,12 @@ impl Days {
141141
}
142142
}
143143

144-
/// Serialization/Deserialization of naive types in alternate formats
144+
/// Serialization/Deserialization of `NaiveDateTime` in alternate formats.
145145
///
146-
/// The various modules in here are intended to be used with serde's [`with`
147-
/// annotation][1] to serialize as something other than the default [RFC
148-
/// 3339][2] format.
146+
/// The various modules in here are intended to be used with serde's [`with` annotation] to
147+
/// serialize as something other than the default ISO 8601 format.
149148
///
150-
/// [1]: https://serde.rs/attributes.html#field-attributes
151-
/// [2]: https://tools.ietf.org/html/rfc3339
149+
/// [`with` annotation]: https://serde.rs/field-attrs.html#with
152150
#[cfg(feature = "serde")]
153151
pub mod serde {
154152
pub use super::datetime::serde::*;

0 commit comments

Comments
 (0)