summaryrefslogtreecommitdiffstats
path: root/vendor/chrono/src/datetime/serde.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/chrono/src/datetime/serde.rs')
-rw-r--r--vendor/chrono/src/datetime/serde.rs77
1 files changed, 50 insertions, 27 deletions
diff --git a/vendor/chrono/src/datetime/serde.rs b/vendor/chrono/src/datetime/serde.rs
index ab0126e2b..72ada0cca 100644
--- a/vendor/chrono/src/datetime/serde.rs
+++ b/vendor/chrono/src/datetime/serde.rs
@@ -122,7 +122,7 @@ impl<'de> de::Deserialize<'de> for DateTime<Local> {
/// # Example:
///
/// ```rust
-/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
+/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::{Deserialize, Serialize};
/// use chrono::serde::ts_nanoseconds;
/// #[derive(Deserialize, Serialize)]
@@ -158,7 +158,7 @@ pub mod ts_nanoseconds {
/// # Example:
///
/// ```rust
- /// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
+ /// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::Serialize;
/// use chrono::serde::ts_nanoseconds::serialize as to_nano_ts;
/// #[derive(Serialize)]
@@ -174,6 +174,7 @@ pub mod ts_nanoseconds {
/// assert_eq!(as_string, r#"{"time":1526522699918355733}"#);
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn serialize<S>(dt: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
@@ -188,18 +189,20 @@ pub mod ts_nanoseconds {
/// # Example:
///
/// ```rust
- /// # use chrono::{DateTime, Utc};
+ /// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_nanoseconds::deserialize as from_nano_ts;
- /// #[derive(Deserialize)]
+ /// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_nano_ts")]
/// time: DateTime<Utc>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355733 }"#)?;
+ /// assert_eq!(my_s, S { time: Utc.timestamp_opt(1526522699, 918355733).unwrap() });
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn deserialize<'de, D>(d: D) -> Result<DateTime<Utc>, D::Error>
where
D: de::Deserializer<'de>,
@@ -245,7 +248,7 @@ pub mod ts_nanoseconds {
/// # Example:
///
/// ```rust
-/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
+/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::{Deserialize, Serialize};
/// use chrono::serde::ts_nanoseconds_option;
/// #[derive(Deserialize, Serialize)]
@@ -280,7 +283,7 @@ pub mod ts_nanoseconds_option {
/// # Example:
///
/// ```rust
- /// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
+ /// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::Serialize;
/// use chrono::serde::ts_nanoseconds_option::serialize as to_nano_tsopt;
/// #[derive(Serialize)]
@@ -296,6 +299,7 @@ pub mod ts_nanoseconds_option {
/// assert_eq!(as_string, r#"{"time":1526522699918355733}"#);
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn serialize<S>(opt: &Option<DateTime<Utc>>, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
@@ -313,18 +317,20 @@ pub mod ts_nanoseconds_option {
/// # Example:
///
/// ```rust
- /// # use chrono::{DateTime, Utc};
+ /// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_nanoseconds_option::deserialize as from_nano_tsopt;
- /// #[derive(Deserialize)]
+ /// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_nano_tsopt")]
/// time: Option<DateTime<Utc>>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355733 }"#)?;
+ /// assert_eq!(my_s, S { time: Utc.timestamp_opt(1526522699, 918355733).single() });
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn deserialize<'de, D>(d: D) -> Result<Option<DateTime<Utc>>, D::Error>
where
D: de::Deserializer<'de>,
@@ -374,7 +380,7 @@ pub mod ts_nanoseconds_option {
/// # Example:
///
/// ```rust
-/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
+/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::{Deserialize, Serialize};
/// use chrono::serde::ts_microseconds;
/// #[derive(Deserialize, Serialize)]
@@ -409,7 +415,7 @@ pub mod ts_microseconds {
/// # Example:
///
/// ```rust
- /// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
+ /// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::Serialize;
/// use chrono::serde::ts_microseconds::serialize as to_micro_ts;
/// #[derive(Serialize)]
@@ -425,6 +431,7 @@ pub mod ts_microseconds {
/// assert_eq!(as_string, r#"{"time":1526522699918355}"#);
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn serialize<S>(dt: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
@@ -439,18 +446,20 @@ pub mod ts_microseconds {
/// # Example:
///
/// ```rust
- /// # use chrono::{DateTime, Utc};
+ /// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_microseconds::deserialize as from_micro_ts;
- /// #[derive(Deserialize)]
+ /// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_micro_ts")]
/// time: DateTime<Utc>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355 }"#)?;
+ /// assert_eq!(my_s, S { time: Utc.timestamp_opt(1526522699, 918355000).unwrap() });
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn deserialize<'de, D>(d: D) -> Result<DateTime<Utc>, D::Error>
where
D: de::Deserializer<'de>,
@@ -496,7 +505,7 @@ pub mod ts_microseconds {
/// # Example:
///
/// ```rust
-/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
+/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::{Deserialize, Serialize};
/// use chrono::serde::ts_microseconds_option;
/// #[derive(Deserialize, Serialize)]
@@ -530,7 +539,7 @@ pub mod ts_microseconds_option {
/// # Example:
///
/// ```rust
- /// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
+ /// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::Serialize;
/// use chrono::serde::ts_microseconds_option::serialize as to_micro_tsopt;
/// #[derive(Serialize)]
@@ -546,6 +555,7 @@ pub mod ts_microseconds_option {
/// assert_eq!(as_string, r#"{"time":1526522699918355}"#);
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn serialize<S>(opt: &Option<DateTime<Utc>>, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
@@ -563,18 +573,20 @@ pub mod ts_microseconds_option {
/// # Example:
///
/// ```rust
- /// # use chrono::{DateTime, Utc};
+ /// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_microseconds_option::deserialize as from_micro_tsopt;
- /// #[derive(Deserialize)]
+ /// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_micro_tsopt")]
/// time: Option<DateTime<Utc>>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355 }"#)?;
+ /// assert_eq!(my_s, S { time: Utc.timestamp_opt(1526522699, 918355000).single() });
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn deserialize<'de, D>(d: D) -> Result<Option<DateTime<Utc>>, D::Error>
where
D: de::Deserializer<'de>,
@@ -624,7 +636,7 @@ pub mod ts_microseconds_option {
/// # Example
///
/// ```rust
-/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
+/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::{Deserialize, Serialize};
/// use chrono::serde::ts_milliseconds;
/// #[derive(Deserialize, Serialize)]
@@ -659,7 +671,7 @@ pub mod ts_milliseconds {
/// # Example:
///
/// ```rust
- /// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
+ /// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::Serialize;
/// use chrono::serde::ts_milliseconds::serialize as to_milli_ts;
/// #[derive(Serialize)]
@@ -675,6 +687,7 @@ pub mod ts_milliseconds {
/// assert_eq!(as_string, r#"{"time":1526522699918}"#);
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn serialize<S>(dt: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
@@ -689,18 +702,20 @@ pub mod ts_milliseconds {
/// # Example:
///
/// ```rust
- /// # use chrono::{DateTime, Utc};
+ /// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_milliseconds::deserialize as from_milli_ts;
- /// #[derive(Deserialize)]
+ /// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_milli_ts")]
/// time: DateTime<Utc>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918 }"#)?;
+ /// assert_eq!(my_s, S { time: Utc.timestamp_opt(1526522699, 918000000).unwrap() });
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn deserialize<'de, D>(d: D) -> Result<DateTime<Utc>, D::Error>
where
D: de::Deserializer<'de>,
@@ -743,7 +758,7 @@ pub mod ts_milliseconds {
/// # Example
///
/// ```rust
-/// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
+/// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::{Deserialize, Serialize};
/// use chrono::serde::ts_milliseconds_option;
/// #[derive(Deserialize, Serialize)]
@@ -777,7 +792,7 @@ pub mod ts_milliseconds_option {
/// # Example:
///
/// ```rust
- /// # use chrono::{TimeZone, DateTime, Utc, NaiveDate};
+ /// # use chrono::{DateTime, Utc, NaiveDate};
/// # use serde_derive::Serialize;
/// use chrono::serde::ts_milliseconds_option::serialize as to_milli_tsopt;
/// #[derive(Serialize)]
@@ -793,6 +808,7 @@ pub mod ts_milliseconds_option {
/// assert_eq!(as_string, r#"{"time":1526522699918}"#);
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn serialize<S>(opt: &Option<DateTime<Utc>>, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
@@ -827,13 +843,14 @@ pub mod ts_milliseconds_option {
/// }
///
/// let my_s: E<S> = serde_json::from_str(r#"{ "time": 1526522699918 }"#)?;
- /// assert_eq!(my_s, E::V(S { time: Some(Utc.timestamp(1526522699, 918000000)) }));
+ /// assert_eq!(my_s, E::V(S { time: Some(Utc.timestamp_opt(1526522699, 918000000).unwrap()) }));
/// let s: E<S> = serde_json::from_str(r#"{ "time": null }"#)?;
/// assert_eq!(s, E::V(S { time: None }));
/// let t: E<S> = serde_json::from_str(r#"{}"#)?;
/// assert_eq!(t, E::V(S { time: None }));
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn deserialize<'de, D>(d: D) -> Result<Option<DateTime<Utc>>, D::Error>
where
D: de::Deserializer<'de>,
@@ -935,6 +952,7 @@ pub mod ts_seconds {
/// assert_eq!(as_string, r#"{"time":1431684000}"#);
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn serialize<S>(dt: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
@@ -949,18 +967,20 @@ pub mod ts_seconds {
/// # Example:
///
/// ```rust
- /// # use chrono::{DateTime, Utc};
+ /// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_seconds::deserialize as from_ts;
- /// #[derive(Deserialize)]
+ /// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_ts")]
/// time: DateTime<Utc>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1431684000 }"#)?;
+ /// assert_eq!(my_s, S { time: Utc.timestamp_opt(1431684000, 0).unwrap() });
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn deserialize<'de, D>(d: D) -> Result<DateTime<Utc>, D::Error>
where
D: de::Deserializer<'de>,
@@ -1050,6 +1070,7 @@ pub mod ts_seconds_option {
/// assert_eq!(as_string, r#"{"time":1431684000}"#);
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn serialize<S>(opt: &Option<DateTime<Utc>>, serializer: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
@@ -1067,18 +1088,20 @@ pub mod ts_seconds_option {
/// # Example:
///
/// ```rust
- /// # use chrono::{DateTime, Utc};
+ /// # use chrono::{DateTime, TimeZone, Utc};
/// # use serde_derive::Deserialize;
/// use chrono::serde::ts_seconds_option::deserialize as from_tsopt;
- /// #[derive(Deserialize)]
+ /// #[derive(Debug, PartialEq, Deserialize)]
/// struct S {
/// #[serde(deserialize_with = "from_tsopt")]
/// time: Option<DateTime<Utc>>
/// }
///
/// let my_s: S = serde_json::from_str(r#"{ "time": 1431684000 }"#)?;
+ /// assert_eq!(my_s, S { time: Utc.timestamp_opt(1431684000, 0).single() });
/// # Ok::<(), serde_json::Error>(())
/// ```
+ #[must_use]
pub fn deserialize<'de, D>(d: D) -> Result<Option<DateTime<Utc>>, D::Error>
where
D: de::Deserializer<'de>,