diff --git a/README.md b/README.md index 48af06cfdb..8ae4aa08e7 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,6 @@ Addition and subtraction is also supported. The following illustrates most supported operations to the date and time: ```rust - use chrono::prelude::*; use chrono::Duration; diff --git a/benches/chrono.rs b/benches/chrono.rs index 01b9caed4f..cc88378eb7 100644 --- a/benches/chrono.rs +++ b/benches/chrono.rs @@ -1,9 +1,6 @@ //! Benchmarks for chrono that just depend on std #![cfg(feature = "__internal_bench")] -extern crate chrono; -extern crate criterion; - use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; use chrono::prelude::*; diff --git a/benches/serde.rs b/benches/serde.rs index b7136efbfb..e9de4408e9 100644 --- a/benches/serde.rs +++ b/benches/serde.rs @@ -1,8 +1,5 @@ #![cfg(feature = "__internal_bench")] -extern crate chrono; -extern crate criterion; - use criterion::{black_box, criterion_group, criterion_main, Criterion}; use chrono::NaiveDateTime; diff --git a/src/datetime/serde.rs b/src/datetime/serde.rs index 1de565ad1b..8f1ce00601 100644 --- a/src/datetime/serde.rs +++ b/src/datetime/serde.rs @@ -119,14 +119,8 @@ impl<'de> de::Deserialize<'de> for DateTime { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate serde_json; -/// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::serde::ts_nanoseconds; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -134,7 +128,6 @@ impl<'de> de::Deserialize<'de> for DateTime { /// time: DateTime /// } /// -/// # fn example() -> Result { /// let time = Utc.ymd(2018, 5, 17).and_hms_nano(02, 04, 59, 918355733); /// let my_s = S { /// time: time.clone(), @@ -144,9 +137,7 @@ impl<'de> de::Deserialize<'de> for DateTime { /// assert_eq!(as_string, r#"{"time":1526522699918355733}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_nanoseconds { use core::fmt; @@ -164,14 +155,8 @@ pub mod ts_nanoseconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; + /// # use serde_derive::Serialize; /// use chrono::serde::ts_nanoseconds::serialize as to_nano_ts; /// #[derive(Serialize)] /// struct S { @@ -179,15 +164,12 @@ pub mod ts_nanoseconds { /// time: DateTime /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: Utc.ymd(2018, 5, 17).and_hms_nano(02, 04, 59, 918355733), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918355733}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(dt: &DateTime, serializer: S) -> Result where @@ -203,14 +185,8 @@ pub mod ts_nanoseconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{DateTime, Utc}; + /// # use serde_derive::Deserialize; /// use chrono::serde::ts_nanoseconds::deserialize as from_nano_ts; /// #[derive(Deserialize)] /// struct S { @@ -218,11 +194,8 @@ pub mod ts_nanoseconds { /// time: DateTime /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355733 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result, D::Error> where @@ -269,14 +242,8 @@ pub mod ts_nanoseconds { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate serde_json; -/// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::serde::ts_nanoseconds_option; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -284,7 +251,6 @@ pub mod ts_nanoseconds { /// time: Option> /// } /// -/// # fn example() -> Result { /// let time = Some(Utc.ymd(2018, 5, 17).and_hms_nano(02, 04, 59, 918355733)); /// let my_s = S { /// time: time.clone(), @@ -294,9 +260,7 @@ pub mod ts_nanoseconds { /// assert_eq!(as_string, r#"{"time":1526522699918355733}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_nanoseconds_option { use core::fmt; @@ -313,14 +277,8 @@ pub mod ts_nanoseconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; + /// # use serde_derive::Serialize; /// use chrono::serde::ts_nanoseconds_option::serialize as to_nano_tsopt; /// #[derive(Serialize)] /// struct S { @@ -328,15 +286,12 @@ pub mod ts_nanoseconds_option { /// time: Option> /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: Some(Utc.ymd(2018, 5, 17).and_hms_nano(02, 04, 59, 918355733)), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918355733}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(opt: &Option>, serializer: S) -> Result where @@ -355,14 +310,8 @@ pub mod ts_nanoseconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{DateTime, Utc}; + /// # use serde_derive::Deserialize; /// use chrono::serde::ts_nanoseconds_option::deserialize as from_nano_tsopt; /// #[derive(Deserialize)] /// struct S { @@ -370,11 +319,8 @@ pub mod ts_nanoseconds_option { /// time: Option> /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355733 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result>, D::Error> where @@ -425,14 +371,8 @@ pub mod ts_nanoseconds_option { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate serde_json; -/// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::serde::ts_microseconds; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -440,7 +380,6 @@ pub mod ts_nanoseconds_option { /// time: DateTime /// } /// -/// # fn example() -> Result { /// let time = Utc.ymd(2018, 5, 17).and_hms_micro(02, 04, 59, 918355); /// let my_s = S { /// time: time.clone(), @@ -450,9 +389,7 @@ pub mod ts_nanoseconds_option { /// assert_eq!(as_string, r#"{"time":1526522699918355}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_microseconds { use core::fmt; @@ -469,14 +406,8 @@ pub mod ts_microseconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; + /// # use serde_derive::Serialize; /// use chrono::serde::ts_microseconds::serialize as to_micro_ts; /// #[derive(Serialize)] /// struct S { @@ -484,15 +415,12 @@ pub mod ts_microseconds { /// time: DateTime /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: Utc.ymd(2018, 5, 17).and_hms_micro(02, 04, 59, 918355), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918355}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(dt: &DateTime, serializer: S) -> Result where @@ -508,14 +436,8 @@ pub mod ts_microseconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{DateTime, Utc}; + /// # use serde_derive::Deserialize; /// use chrono::serde::ts_microseconds::deserialize as from_micro_ts; /// #[derive(Deserialize)] /// struct S { @@ -523,11 +445,8 @@ pub mod ts_microseconds { /// time: DateTime /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result, D::Error> where @@ -574,14 +493,8 @@ pub mod ts_microseconds { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate serde_json; -/// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::serde::ts_microseconds_option; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -589,7 +502,6 @@ pub mod ts_microseconds { /// time: Option> /// } /// -/// # fn example() -> Result { /// let time = Some(Utc.ymd(2018, 5, 17).and_hms_micro(02, 04, 59, 918355)); /// let my_s = S { /// time: time.clone(), @@ -599,9 +511,7 @@ pub mod ts_microseconds { /// assert_eq!(as_string, r#"{"time":1526522699918355}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_microseconds_option { use core::fmt; @@ -617,14 +527,8 @@ pub mod ts_microseconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; + /// # use serde_derive::Serialize; /// use chrono::serde::ts_microseconds_option::serialize as to_micro_tsopt; /// #[derive(Serialize)] /// struct S { @@ -632,15 +536,12 @@ pub mod ts_microseconds_option { /// time: Option> /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: Some(Utc.ymd(2018, 5, 17).and_hms_micro(02, 04, 59, 918355)), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918355}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(opt: &Option>, serializer: S) -> Result where @@ -659,14 +560,8 @@ pub mod ts_microseconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{DateTime, Utc}; + /// # use serde_derive::Deserialize; /// use chrono::serde::ts_microseconds_option::deserialize as from_micro_tsopt; /// #[derive(Deserialize)] /// struct S { @@ -674,11 +569,8 @@ pub mod ts_microseconds_option { /// time: Option> /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result>, D::Error> where @@ -729,14 +621,8 @@ pub mod ts_microseconds_option { /// # Example /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate serde_json; -/// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::serde::ts_milliseconds; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -744,7 +630,6 @@ pub mod ts_microseconds_option { /// time: DateTime /// } /// -/// # fn example() -> Result { /// let time = Utc.ymd(2018, 5, 17).and_hms_milli(02, 04, 59, 918); /// let my_s = S { /// time: time.clone(), @@ -754,9 +639,7 @@ pub mod ts_microseconds_option { /// assert_eq!(as_string, r#"{"time":1526522699918}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_milliseconds { use core::fmt; @@ -773,14 +656,8 @@ pub mod ts_milliseconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; + /// # use serde_derive::Serialize; /// use chrono::serde::ts_milliseconds::serialize as to_milli_ts; /// #[derive(Serialize)] /// struct S { @@ -788,15 +665,12 @@ pub mod ts_milliseconds { /// time: DateTime /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: Utc.ymd(2018, 5, 17).and_hms_milli(02, 04, 59, 918), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(dt: &DateTime, serializer: S) -> Result where @@ -812,14 +686,8 @@ pub mod ts_milliseconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{DateTime, Utc}; + /// # use serde_derive::Deserialize; /// use chrono::serde::ts_milliseconds::deserialize as from_milli_ts; /// #[derive(Deserialize)] /// struct S { @@ -827,11 +695,8 @@ pub mod ts_milliseconds { /// time: DateTime /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result, D::Error> where @@ -875,14 +740,8 @@ pub mod ts_milliseconds { /// # Example /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate serde_json; -/// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::serde::ts_milliseconds_option; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -890,7 +749,6 @@ pub mod ts_milliseconds { /// time: Option> /// } /// -/// # fn example() -> Result { /// let time = Some(Utc.ymd(2018, 5, 17).and_hms_milli(02, 04, 59, 918)); /// let my_s = S { /// time: time.clone(), @@ -900,9 +758,7 @@ pub mod ts_milliseconds { /// assert_eq!(as_string, r#"{"time":1526522699918}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_milliseconds_option { use core::fmt; @@ -918,14 +774,8 @@ pub mod ts_milliseconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; + /// # use serde_derive::Serialize; /// use chrono::serde::ts_milliseconds_option::serialize as to_milli_tsopt; /// #[derive(Serialize)] /// struct S { @@ -933,15 +783,12 @@ pub mod ts_milliseconds_option { /// time: Option> /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: Some(Utc.ymd(2018, 5, 17).and_hms_milli(02, 04, 59, 918)), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(opt: &Option>, serializer: S) -> Result where @@ -960,14 +807,8 @@ pub mod ts_milliseconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; - /// # use chrono::prelude::*; + /// # use chrono::{TimeZone, DateTime, Utc}; + /// # use serde_derive::Deserialize; /// use chrono::serde::ts_milliseconds_option::deserialize as from_milli_tsopt; /// /// #[derive(Deserialize, PartialEq, Debug)] @@ -982,16 +823,13 @@ pub mod ts_milliseconds_option { /// time: Option> /// } /// - /// # fn example() -> Result<(), serde_json::Error> { /// let my_s: E = serde_json::from_str(r#"{ "time": 1526522699918 }"#)?; /// assert_eq!(my_s, E::V(S { time: Some(Utc.timestamp(1526522699, 918000000)) })); /// let s: E = serde_json::from_str(r#"{ "time": null }"#)?; /// assert_eq!(s, E::V(S { time: None })); /// let t: E = serde_json::from_str(r#"{}"#)?; /// assert_eq!(t, E::V(S { time: None })); - /// # Ok(()) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result>, D::Error> where @@ -1043,14 +881,8 @@ pub mod ts_milliseconds_option { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate serde_json; -/// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::serde::ts_seconds; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -1058,7 +890,6 @@ pub mod ts_milliseconds_option { /// time: DateTime /// } /// -/// # fn example() -> Result { /// let time = Utc.ymd(2015, 5, 15).and_hms(10, 0, 0); /// let my_s = S { /// time: time.clone(), @@ -1068,9 +899,7 @@ pub mod ts_milliseconds_option { /// assert_eq!(as_string, r#"{"time":1431684000}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_seconds { use core::fmt; @@ -1087,14 +916,8 @@ pub mod ts_seconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; + /// # use serde_derive::Serialize; /// use chrono::serde::ts_seconds::serialize as to_ts; /// #[derive(Serialize)] /// struct S { @@ -1102,15 +925,12 @@ pub mod ts_seconds { /// time: DateTime /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: Utc.ymd(2015, 5, 15).and_hms(10, 0, 0), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1431684000}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(dt: &DateTime, serializer: S) -> Result where @@ -1126,14 +946,8 @@ pub mod ts_seconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{DateTime, Utc}; + /// # use serde_derive::Deserialize; /// use chrono::serde::ts_seconds::deserialize as from_ts; /// #[derive(Deserialize)] /// struct S { @@ -1141,11 +955,8 @@ pub mod ts_seconds { /// time: DateTime /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1431684000 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result, D::Error> where @@ -1186,14 +997,8 @@ pub mod ts_seconds { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate serde_json; -/// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::serde::ts_seconds_option; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -1201,7 +1006,6 @@ pub mod ts_seconds { /// time: Option> /// } /// -/// # fn example() -> Result { /// let time = Some(Utc.ymd(2015, 5, 15).and_hms(10, 0, 0)); /// let my_s = S { /// time: time.clone(), @@ -1211,9 +1015,7 @@ pub mod ts_seconds { /// assert_eq!(as_string, r#"{"time":1431684000}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_seconds_option { use core::fmt; @@ -1229,14 +1031,8 @@ pub mod ts_seconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{TimeZone, DateTime, Utc}; + /// # use serde_derive::Serialize; /// use chrono::serde::ts_seconds_option::serialize as to_tsopt; /// #[derive(Serialize)] /// struct S { @@ -1244,15 +1040,12 @@ pub mod ts_seconds_option { /// time: Option> /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: Some(Utc.ymd(2015, 5, 15).and_hms(10, 0, 0)), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1431684000}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(opt: &Option>, serializer: S) -> Result where @@ -1271,14 +1064,8 @@ pub mod ts_seconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::{DateTime, Utc}; + /// # use serde_derive::Deserialize; /// use chrono::serde::ts_seconds_option::deserialize as from_tsopt; /// #[derive(Deserialize)] /// struct S { @@ -1286,11 +1073,8 @@ pub mod ts_seconds_option { /// time: Option> /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1431684000 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result>, D::Error> where @@ -1334,23 +1118,18 @@ pub mod ts_seconds_option { } } -#[cfg(test)] -extern crate bincode; -#[cfg(test)] -extern crate serde_json; - #[test] fn test_serde_serialize() { - super::test_encodable_json(self::serde_json::to_string, self::serde_json::to_string); + super::test_encodable_json(serde_json::to_string, serde_json::to_string); } #[cfg(feature = "clock")] #[test] fn test_serde_deserialize() { super::test_decodable_json( - |input| self::serde_json::from_str(input), - |input| self::serde_json::from_str(input), - |input| self::serde_json::from_str(input), + |input| serde_json::from_str(input), + |input| serde_json::from_str(input), + |input| serde_json::from_str(input), ); } @@ -1358,7 +1137,7 @@ fn test_serde_deserialize() { fn test_serde_bincode() { // Bincode is relevant to test separately from JSON because // it is not self-describing. - use self::bincode::{deserialize, serialize, Infinite}; + use bincode::{deserialize, serialize, Infinite}; let dt = Utc.ymd(2014, 7, 24).and_hms(12, 34, 6); let encoded = serialize(&dt, Infinite).unwrap(); diff --git a/src/format/mod.rs b/src/format/mod.rs index 5d720c0b57..893496a035 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -18,8 +18,6 @@ //! # Example //! ```rust //! # use std::error::Error; -//! # -//! # fn main() -> Result<(), Box> { //! use chrono::prelude::*; //! //! let date_time = Utc.ymd(2020, 11, 10).and_hms(0, 1, 32); @@ -29,8 +27,7 @@ //! //! let parsed = Utc.datetime_from_str(&formatted, "%Y-%m-%d %H:%M:%S")?; //! assert_eq!(parsed, date_time); -//! # Ok(()) -//! # } +//! # Ok::<(), chrono::ParseError>(()) //! ``` #[cfg(feature = "alloc")] diff --git a/src/lib.rs b/src/lib.rs index 80065c3051..2808abb5ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -173,9 +173,6 @@ //! The following illustrates most supported operations to the date and time: //! //! ```rust -//! # extern crate chrono; -//! -//! # fn main() { //! use chrono::prelude::*; //! use chrono::Duration; //! @@ -210,7 +207,6 @@ //! Utc.ymd(2001, 9, 9).and_hms(1, 46, 40)); //! assert_eq!(Utc.ymd(1970, 1, 1).and_hms(0, 0, 0) - Duration::seconds(1_000_000_000), //! Utc.ymd(1938, 4, 24).and_hms(22, 13, 20)); -//! # } //! ``` //! //! ### Formatting and Parsing diff --git a/src/month.rs b/src/month.rs index 624cf3ea03..8d549d4a3d 100644 --- a/src/month.rs +++ b/src/month.rs @@ -7,7 +7,6 @@ use core::fmt; /// /// It is possible to convert from a date to a month independently /// ``` -/// # extern crate num_traits; /// use num_traits::FromPrimitive; /// use chrono::prelude::*; /// let date = Utc.ymd(2019, 10, 28).and_hms(9, 10, 11); diff --git a/src/naive/date.rs b/src/naive/date.rs index 50ba1129a8..7e3e0530c1 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -878,7 +878,6 @@ impl NaiveDate { /// # Example /// /// ``` - /// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveDate}; /// use chrono::naive::MAX_DATE; /// @@ -890,7 +889,6 @@ impl NaiveDate { /// assert_eq!(d.checked_add_signed(Duration::days(1_000_000_000)), None); /// assert_eq!(d.checked_add_signed(Duration::days(-1_000_000_000)), None); /// assert_eq!(MAX_DATE.checked_add_signed(Duration::days(1)), None); - /// # } /// ``` pub fn checked_add_signed(self, rhs: OldDuration) -> Option { let year = self.year(); @@ -912,7 +910,6 @@ impl NaiveDate { /// # Example /// /// ``` - /// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveDate}; /// use chrono::naive::MIN_DATE; /// @@ -924,7 +921,6 @@ impl NaiveDate { /// assert_eq!(d.checked_sub_signed(Duration::days(1_000_000_000)), None); /// assert_eq!(d.checked_sub_signed(Duration::days(-1_000_000_000)), None); /// assert_eq!(MIN_DATE.checked_sub_signed(Duration::days(1)), None); - /// # } /// ``` pub fn checked_sub_signed(self, rhs: OldDuration) -> Option { let year = self.year(); @@ -948,7 +944,6 @@ impl NaiveDate { /// # Example /// /// ``` - /// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveDate}; /// /// let from_ymd = NaiveDate::from_ymd; @@ -961,7 +956,6 @@ impl NaiveDate { /// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2013, 1, 1)), Duration::days(365)); /// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2010, 1, 1)), Duration::days(365*4 + 1)); /// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(1614, 1, 1)), Duration::days(365*400 + 97)); - /// # } /// ``` pub fn signed_duration_since(self, rhs: NaiveDate) -> OldDuration { let year1 = self.year(); @@ -1454,7 +1448,6 @@ impl Datelike for NaiveDate { /// # Example /// /// ``` -/// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveDate}; /// /// let from_ymd = NaiveDate::from_ymd; @@ -1467,7 +1460,6 @@ impl Datelike for NaiveDate { /// assert_eq!(from_ymd(2014, 1, 1) + Duration::days(364), from_ymd(2014, 12, 31)); /// assert_eq!(from_ymd(2014, 1, 1) + Duration::days(365*4 + 1), from_ymd(2018, 1, 1)); /// assert_eq!(from_ymd(2014, 1, 1) + Duration::days(365*400 + 97), from_ymd(2414, 1, 1)); -/// # } /// ``` impl Add for NaiveDate { type Output = NaiveDate; @@ -1495,7 +1487,6 @@ impl AddAssign for NaiveDate { /// # Example /// /// ``` -/// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveDate}; /// /// let from_ymd = NaiveDate::from_ymd; @@ -1508,7 +1499,6 @@ impl AddAssign for NaiveDate { /// assert_eq!(from_ymd(2014, 1, 1) - Duration::days(364), from_ymd(2013, 1, 2)); /// assert_eq!(from_ymd(2014, 1, 1) - Duration::days(365*4 + 1), from_ymd(2010, 1, 1)); /// assert_eq!(from_ymd(2014, 1, 1) - Duration::days(365*400 + 97), from_ymd(1614, 1, 1)); -/// # } /// ``` impl Sub for NaiveDate { type Output = NaiveDate; @@ -1538,7 +1528,6 @@ impl SubAssign for NaiveDate { /// # Example /// /// ``` -/// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveDate}; /// /// let from_ymd = NaiveDate::from_ymd; @@ -1550,7 +1539,6 @@ impl SubAssign for NaiveDate { /// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 1, 1), Duration::days(365)); /// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2010, 1, 1), Duration::days(365*4 + 1)); /// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(1614, 1, 1), Duration::days(365*400 + 97)); -/// # } /// ``` impl Sub for NaiveDate { type Output = OldDuration; diff --git a/src/naive/datetime/mod.rs b/src/naive/datetime/mod.rs index cd1853c338..950fa239e7 100644 --- a/src/naive/datetime/mod.rs +++ b/src/naive/datetime/mod.rs @@ -468,7 +468,6 @@ impl NaiveDateTime { /// # Example /// /// ``` - /// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveDate}; /// /// let from_ymd = NaiveDate::from_ymd; @@ -489,24 +488,20 @@ impl NaiveDateTime { /// let hmsm = |h, m, s, milli| d.and_hms_milli(h, m, s, milli); /// assert_eq!(hmsm(3, 5, 7, 980).checked_add_signed(Duration::milliseconds(450)), /// Some(hmsm(3, 5, 8, 430))); - /// # } /// ``` /// /// Overflow returns `None`. /// /// ``` - /// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveDate}; /// # let hms = |h, m, s| NaiveDate::from_ymd(2016, 7, 8).and_hms(h, m, s); /// assert_eq!(hms(3, 5, 7).checked_add_signed(Duration::days(1_000_000_000)), None); - /// # } /// ``` /// /// Leap seconds are handled, /// but the addition assumes that it is the only leap second happened. /// /// ``` - /// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveDate}; /// # let from_ymd = NaiveDate::from_ymd; /// # let hmsm = |h, m, s, milli| from_ymd(2016, 7, 8).and_hms_milli(h, m, s, milli); @@ -525,7 +520,6 @@ impl NaiveDateTime { /// Some(hmsm(3, 5, 50, 300))); /// assert_eq!(leap.checked_add_signed(Duration::days(1)), /// Some(from_ymd(2016, 7, 9).and_hms_milli(3, 5, 59, 300))); - /// # } /// ``` pub fn checked_add_signed(self, rhs: OldDuration) -> Option { let (time, rhs) = self.time.overflowing_add_signed(rhs); @@ -551,7 +545,6 @@ impl NaiveDateTime { /// # Example /// /// ``` - /// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveDate}; /// /// let from_ymd = NaiveDate::from_ymd; @@ -572,24 +565,20 @@ impl NaiveDateTime { /// let hmsm = |h, m, s, milli| d.and_hms_milli(h, m, s, milli); /// assert_eq!(hmsm(3, 5, 7, 450).checked_sub_signed(Duration::milliseconds(670)), /// Some(hmsm(3, 5, 6, 780))); - /// # } /// ``` /// /// Overflow returns `None`. /// /// ``` - /// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveDate}; /// # let hms = |h, m, s| NaiveDate::from_ymd(2016, 7, 8).and_hms(h, m, s); /// assert_eq!(hms(3, 5, 7).checked_sub_signed(Duration::days(1_000_000_000)), None); - /// # } /// ``` /// /// Leap seconds are handled, /// but the subtraction assumes that it is the only leap second happened. /// /// ``` - /// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveDate}; /// # let from_ymd = NaiveDate::from_ymd; /// # let hmsm = |h, m, s, milli| from_ymd(2016, 7, 8).and_hms_milli(h, m, s, milli); @@ -604,7 +593,6 @@ impl NaiveDateTime { /// Some(hmsm(3, 5, 0, 300))); /// assert_eq!(leap.checked_sub_signed(Duration::days(1)), /// Some(from_ymd(2016, 7, 7).and_hms_milli(3, 6, 0, 300))); - /// # } /// ``` pub fn checked_sub_signed(self, rhs: OldDuration) -> Option { let (time, rhs) = self.time.overflowing_sub_signed(rhs); @@ -630,7 +618,6 @@ impl NaiveDateTime { /// # Example /// /// ``` - /// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveDate}; /// /// let from_ymd = NaiveDate::from_ymd; @@ -643,14 +630,12 @@ impl NaiveDateTime { /// let d0 = from_ymd(2016, 1, 1); /// assert_eq!(d.and_hms_milli(0, 7, 6, 500).signed_duration_since(d0.and_hms(0, 0, 0)), /// Duration::seconds(189 * 86_400 + 7 * 60 + 6) + Duration::milliseconds(500)); - /// # } /// ``` /// /// Leap seconds are handled, but the subtraction assumes that /// there were no other leap seconds happened. /// /// ``` - /// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveDate}; /// # let from_ymd = NaiveDate::from_ymd; /// let leap = from_ymd(2015, 6, 30).and_hms_milli(23, 59, 59, 1_500); @@ -658,7 +643,6 @@ impl NaiveDateTime { /// Duration::seconds(3600) + Duration::milliseconds(500)); /// assert_eq!(from_ymd(2015, 7, 1).and_hms(1, 0, 0).signed_duration_since(leap), /// Duration::seconds(3600) - Duration::milliseconds(500)); - /// # } /// ``` pub fn signed_duration_since(self, rhs: NaiveDateTime) -> OldDuration { self.date.signed_duration_since(rhs.date) + self.time.signed_duration_since(rhs.time) @@ -1227,7 +1211,6 @@ impl Timelike for NaiveDateTime { /// # Example /// /// ``` -/// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveDate}; /// /// let from_ymd = NaiveDate::from_ymd; @@ -1245,14 +1228,12 @@ impl Timelike for NaiveDateTime { /// /// let hmsm = |h, m, s, milli| d.and_hms_milli(h, m, s, milli); /// assert_eq!(hmsm(3, 5, 7, 980) + Duration::milliseconds(450), hmsm(3, 5, 8, 430)); -/// # } /// ``` /// /// Leap seconds are handled, /// but the addition assumes that it is the only leap second happened. /// /// ``` -/// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveDate}; /// # let from_ymd = NaiveDate::from_ymd; /// # let hmsm = |h, m, s, milli| from_ymd(2016, 7, 8).and_hms_milli(h, m, s, milli); @@ -1265,7 +1246,6 @@ impl Timelike for NaiveDateTime { /// assert_eq!(leap + Duration::seconds(-10), hmsm(3, 5, 50, 300)); /// assert_eq!(leap + Duration::days(1), /// from_ymd(2016, 7, 9).and_hms_milli(3, 5, 59, 300)); -/// # } /// ``` impl Add for NaiveDateTime { type Output = NaiveDateTime; @@ -1297,7 +1277,6 @@ impl AddAssign for NaiveDateTime { /// # Example /// /// ``` -/// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveDate}; /// /// let from_ymd = NaiveDate::from_ymd; @@ -1315,14 +1294,12 @@ impl AddAssign for NaiveDateTime { /// /// let hmsm = |h, m, s, milli| d.and_hms_milli(h, m, s, milli); /// assert_eq!(hmsm(3, 5, 7, 450) - Duration::milliseconds(670), hmsm(3, 5, 6, 780)); -/// # } /// ``` /// /// Leap seconds are handled, /// but the subtraction assumes that it is the only leap second happened. /// /// ``` -/// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveDate}; /// # let from_ymd = NaiveDate::from_ymd; /// # let hmsm = |h, m, s, milli| from_ymd(2016, 7, 8).and_hms_milli(h, m, s, milli); @@ -1333,7 +1310,6 @@ impl AddAssign for NaiveDateTime { /// assert_eq!(leap - Duration::seconds(60), hmsm(3, 5, 0, 300)); /// assert_eq!(leap - Duration::days(1), /// from_ymd(2016, 7, 7).and_hms_milli(3, 6, 0, 300)); -/// # } /// ``` impl Sub for NaiveDateTime { type Output = NaiveDateTime; @@ -1365,7 +1341,6 @@ impl SubAssign for NaiveDateTime { /// # Example /// /// ``` -/// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveDate}; /// /// let from_ymd = NaiveDate::from_ymd; @@ -1377,14 +1352,12 @@ impl SubAssign for NaiveDateTime { /// let d0 = from_ymd(2016, 1, 1); /// assert_eq!(d.and_hms_milli(0, 7, 6, 500) - d0.and_hms(0, 0, 0), /// Duration::seconds(189 * 86_400 + 7 * 60 + 6) + Duration::milliseconds(500)); -/// # } /// ``` /// /// Leap seconds are handled, but the subtraction assumes that no other leap /// seconds happened. /// /// ``` -/// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveDate}; /// # let from_ymd = NaiveDate::from_ymd; /// let leap = from_ymd(2015, 6, 30).and_hms_milli(23, 59, 59, 1_500); @@ -1392,7 +1365,6 @@ impl SubAssign for NaiveDateTime { /// Duration::seconds(3600) + Duration::milliseconds(500)); /// assert_eq!(from_ymd(2015, 7, 1).and_hms(1, 0, 0) - leap, /// Duration::seconds(3600) - Duration::milliseconds(500)); -/// # } /// ``` impl Sub for NaiveDateTime { type Output = OldDuration; diff --git a/src/naive/datetime/serde.rs b/src/naive/datetime/serde.rs index a30d43b552..27910fa7d3 100644 --- a/src/naive/datetime/serde.rs +++ b/src/naive/datetime/serde.rs @@ -58,15 +58,8 @@ impl<'de> de::Deserialize<'de> for NaiveDateTime { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # extern crate serde_json; -/// # extern crate serde; -/// # extern crate chrono; /// # use chrono::{NaiveDate, NaiveDateTime}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::naive::serde::ts_nanoseconds; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -74,7 +67,6 @@ impl<'de> de::Deserialize<'de> for NaiveDateTime { /// time: NaiveDateTime /// } /// -/// # fn example() -> Result { /// let time = NaiveDate::from_ymd(2018, 5, 17).and_hms_nano(02, 04, 59, 918355733); /// let my_s = S { /// time: time.clone(), @@ -84,9 +76,7 @@ impl<'de> de::Deserialize<'de> for NaiveDateTime { /// assert_eq!(as_string, r#"{"time":1526522699918355733}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_nanoseconds { use core::fmt; @@ -102,16 +92,8 @@ pub mod ts_nanoseconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # #[macro_use] extern crate serde; - /// # extern crate chrono; /// # use chrono::{NaiveDate, NaiveDateTime}; - /// # use serde::Serialize; + /// # use serde_derive::Serialize; /// use chrono::naive::serde::ts_nanoseconds::serialize as to_nano_ts; /// #[derive(Serialize)] /// struct S { @@ -119,15 +101,12 @@ pub mod ts_nanoseconds { /// time: NaiveDateTime /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: NaiveDate::from_ymd(2018, 5, 17).and_hms_nano(02, 04, 59, 918355733), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918355733}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(dt: &NaiveDateTime, serializer: S) -> Result where @@ -143,16 +122,8 @@ pub mod ts_nanoseconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate serde; - /// # extern crate chrono; /// # use chrono::NaiveDateTime; - /// # use serde::Deserialize; + /// # use serde_derive::Deserialize; /// use chrono::naive::serde::ts_nanoseconds::deserialize as from_nano_ts; /// #[derive(Deserialize)] /// struct S { @@ -160,11 +131,8 @@ pub mod ts_nanoseconds { /// time: NaiveDateTime /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355733 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result where @@ -210,14 +178,8 @@ pub mod ts_nanoseconds { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate serde_json; -/// # extern crate chrono; /// # use chrono::naive::{NaiveDate, NaiveDateTime}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::naive::serde::ts_nanoseconds_option; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -225,7 +187,6 @@ pub mod ts_nanoseconds { /// time: Option /// } /// -/// # fn example() -> Result { /// let time = Some(NaiveDate::from_ymd(2018, 5, 17).and_hms_nano(02, 04, 59, 918355733)); /// let my_s = S { /// time: time.clone(), @@ -235,9 +196,7 @@ pub mod ts_nanoseconds { /// assert_eq!(as_string, r#"{"time":1526522699918355733}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_nanoseconds_option { use core::fmt; @@ -253,14 +212,8 @@ pub mod ts_nanoseconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::naive::{NaiveDate, NaiveDateTime}; + /// # use serde_derive::Serialize; /// use chrono::naive::serde::ts_nanoseconds_option::serialize as to_nano_tsopt; /// #[derive(Serialize)] /// struct S { @@ -268,15 +221,12 @@ pub mod ts_nanoseconds_option { /// time: Option /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: Some(NaiveDate::from_ymd(2018, 5, 17).and_hms_nano(02, 04, 59, 918355733)), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918355733}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(opt: &Option, serializer: S) -> Result where @@ -295,14 +245,8 @@ pub mod ts_nanoseconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::naive::{NaiveDate, NaiveDateTime}; + /// # use serde_derive::Deserialize; /// use chrono::naive::serde::ts_nanoseconds_option::deserialize as from_nano_tsopt; /// #[derive(Deserialize)] /// struct S { @@ -310,11 +254,8 @@ pub mod ts_nanoseconds_option { /// time: Option /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355733 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result, D::Error> where @@ -363,15 +304,8 @@ pub mod ts_nanoseconds_option { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # extern crate serde_json; -/// # extern crate serde; -/// # extern crate chrono; /// # use chrono::{NaiveDate, NaiveDateTime}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::naive::serde::ts_microseconds; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -379,7 +313,6 @@ pub mod ts_nanoseconds_option { /// time: NaiveDateTime /// } /// -/// # fn example() -> Result { /// let time = NaiveDate::from_ymd(2018, 5, 17).and_hms_micro(02, 04, 59, 918355); /// let my_s = S { /// time: time.clone(), @@ -389,9 +322,7 @@ pub mod ts_nanoseconds_option { /// assert_eq!(as_string, r#"{"time":1526522699918355}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_microseconds { use core::fmt; @@ -407,16 +338,8 @@ pub mod ts_microseconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # #[macro_use] extern crate serde; - /// # extern crate chrono; /// # use chrono::{NaiveDate, NaiveDateTime}; - /// # use serde::Serialize; + /// # use serde_derive::Serialize; /// use chrono::naive::serde::ts_microseconds::serialize as to_micro_ts; /// #[derive(Serialize)] /// struct S { @@ -424,15 +347,12 @@ pub mod ts_microseconds { /// time: NaiveDateTime /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: NaiveDate::from_ymd(2018, 5, 17).and_hms_micro(02, 04, 59, 918355), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918355}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(dt: &NaiveDateTime, serializer: S) -> Result where @@ -448,16 +368,8 @@ pub mod ts_microseconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate serde; - /// # extern crate chrono; /// # use chrono::NaiveDateTime; - /// # use serde::Deserialize; + /// # use serde_derive::Deserialize; /// use chrono::naive::serde::ts_microseconds::deserialize as from_micro_ts; /// #[derive(Deserialize)] /// struct S { @@ -465,11 +377,8 @@ pub mod ts_microseconds { /// time: NaiveDateTime /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result where @@ -518,14 +427,8 @@ pub mod ts_microseconds { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate serde_json; -/// # extern crate chrono; /// # use chrono::naive::{NaiveDate, NaiveDateTime}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::naive::serde::ts_microseconds_option; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -533,7 +436,6 @@ pub mod ts_microseconds { /// time: Option /// } /// -/// # fn example() -> Result { /// let time = Some(NaiveDate::from_ymd(2018, 5, 17).and_hms_micro(02, 04, 59, 918355)); /// let my_s = S { /// time: time.clone(), @@ -543,9 +445,7 @@ pub mod ts_microseconds { /// assert_eq!(as_string, r#"{"time":1526522699918355}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_microseconds_option { use core::fmt; @@ -561,14 +461,8 @@ pub mod ts_microseconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::naive::{NaiveDate, NaiveDateTime}; + /// # use serde_derive::Serialize; /// use chrono::naive::serde::ts_microseconds_option::serialize as to_micro_tsopt; /// #[derive(Serialize)] /// struct S { @@ -576,15 +470,12 @@ pub mod ts_microseconds_option { /// time: Option /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: Some(NaiveDate::from_ymd(2018, 5, 17).and_hms_micro(02, 04, 59, 918355)), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918355}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(opt: &Option, serializer: S) -> Result where @@ -603,14 +494,8 @@ pub mod ts_microseconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::naive::{NaiveDate, NaiveDateTime}; + /// # use serde_derive::Deserialize; /// use chrono::naive::serde::ts_microseconds_option::deserialize as from_micro_tsopt; /// #[derive(Deserialize)] /// struct S { @@ -618,11 +503,8 @@ pub mod ts_microseconds_option { /// time: Option /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result, D::Error> where @@ -671,15 +553,8 @@ pub mod ts_microseconds_option { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # extern crate serde_json; -/// # extern crate serde; -/// # extern crate chrono; /// # use chrono::{NaiveDate, NaiveDateTime}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::naive::serde::ts_milliseconds; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -687,7 +562,6 @@ pub mod ts_microseconds_option { /// time: NaiveDateTime /// } /// -/// # fn example() -> Result { /// let time = NaiveDate::from_ymd(2018, 5, 17).and_hms_milli(02, 04, 59, 918); /// let my_s = S { /// time: time.clone(), @@ -697,9 +571,7 @@ pub mod ts_microseconds_option { /// assert_eq!(as_string, r#"{"time":1526522699918}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_milliseconds { use core::fmt; @@ -715,16 +587,8 @@ pub mod ts_milliseconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # #[macro_use] extern crate serde; - /// # extern crate chrono; /// # use chrono::{NaiveDate, NaiveDateTime}; - /// # use serde::Serialize; + /// # use serde_derive::Serialize; /// use chrono::naive::serde::ts_milliseconds::serialize as to_milli_ts; /// #[derive(Serialize)] /// struct S { @@ -732,15 +596,12 @@ pub mod ts_milliseconds { /// time: NaiveDateTime /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: NaiveDate::from_ymd(2018, 5, 17).and_hms_milli(02, 04, 59, 918), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(dt: &NaiveDateTime, serializer: S) -> Result where @@ -756,16 +617,8 @@ pub mod ts_milliseconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate serde; - /// # extern crate chrono; /// # use chrono::NaiveDateTime; - /// # use serde::Deserialize; + /// # use serde_derive::Deserialize; /// use chrono::naive::serde::ts_milliseconds::deserialize as from_milli_ts; /// #[derive(Deserialize)] /// struct S { @@ -773,11 +626,8 @@ pub mod ts_milliseconds { /// time: NaiveDateTime /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result where @@ -823,14 +673,8 @@ pub mod ts_milliseconds { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate serde_json; -/// # extern crate chrono; /// # use chrono::naive::{NaiveDate, NaiveDateTime}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::naive::serde::ts_milliseconds_option; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -838,7 +682,6 @@ pub mod ts_milliseconds { /// time: Option /// } /// -/// # fn example() -> Result { /// let time = Some(NaiveDate::from_ymd(2018, 5, 17).and_hms_milli(02, 04, 59, 918)); /// let my_s = S { /// time: time.clone(), @@ -848,9 +691,7 @@ pub mod ts_milliseconds { /// assert_eq!(as_string, r#"{"time":1526522699918}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_milliseconds_option { use core::fmt; @@ -866,14 +707,8 @@ pub mod ts_milliseconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::naive::{NaiveDate, NaiveDateTime}; + /// # use serde_derive::Serialize; /// use chrono::naive::serde::ts_milliseconds_option::serialize as to_milli_tsopt; /// #[derive(Serialize)] /// struct S { @@ -881,15 +716,12 @@ pub mod ts_milliseconds_option { /// time: Option /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: Some(NaiveDate::from_ymd(2018, 5, 17).and_hms_milli(02, 04, 59, 918)), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(opt: &Option, serializer: S) -> Result where @@ -908,14 +740,8 @@ pub mod ts_milliseconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::naive::{NaiveDate, NaiveDateTime}; + /// # use serde_derive::Deserialize; /// use chrono::naive::serde::ts_milliseconds_option::deserialize as from_milli_tsopt; /// #[derive(Deserialize)] /// struct S { @@ -923,11 +749,8 @@ pub mod ts_milliseconds_option { /// time: Option /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result, D::Error> where @@ -976,15 +799,8 @@ pub mod ts_milliseconds_option { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # extern crate serde_json; -/// # extern crate serde; -/// # extern crate chrono; /// # use chrono::{NaiveDate, NaiveDateTime}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::naive::serde::ts_seconds; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -992,7 +808,6 @@ pub mod ts_milliseconds_option { /// time: NaiveDateTime /// } /// -/// # fn example() -> Result { /// let time = NaiveDate::from_ymd(2015, 5, 15).and_hms(10, 0, 0); /// let my_s = S { /// time: time.clone(), @@ -1002,9 +817,7 @@ pub mod ts_milliseconds_option { /// assert_eq!(as_string, r#"{"time":1431684000}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_seconds { use core::fmt; @@ -1020,16 +833,8 @@ pub mod ts_seconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # #[macro_use] extern crate serde; - /// # extern crate chrono; /// # use chrono::{NaiveDate, NaiveDateTime}; - /// # use serde::Serialize; + /// # use serde_derive::Serialize; /// use chrono::naive::serde::ts_seconds::serialize as to_ts; /// #[derive(Serialize)] /// struct S { @@ -1037,15 +842,12 @@ pub mod ts_seconds { /// time: NaiveDateTime /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: NaiveDate::from_ymd(2015, 5, 15).and_hms(10, 0, 0), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1431684000}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(dt: &NaiveDateTime, serializer: S) -> Result where @@ -1061,16 +863,8 @@ pub mod ts_seconds { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate serde; - /// # extern crate chrono; /// # use chrono::NaiveDateTime; - /// # use serde::Deserialize; + /// # use serde_derive::Deserialize; /// use chrono::naive::serde::ts_seconds::deserialize as from_ts; /// #[derive(Deserialize)] /// struct S { @@ -1078,11 +872,8 @@ pub mod ts_seconds { /// time: NaiveDateTime /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1431684000 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result where @@ -1125,14 +916,8 @@ pub mod ts_seconds { /// # Example: /// /// ```rust -/// # // We mark this ignored so that we can test on 1.13 (which does not -/// # // support custom derive), and run tests with --ignored on beta and -/// # // nightly to actually trigger these. -/// # -/// # #[macro_use] extern crate serde_derive; -/// # #[macro_use] extern crate serde_json; -/// # extern crate chrono; /// # use chrono::naive::{NaiveDate, NaiveDateTime}; +/// # use serde_derive::{Deserialize, Serialize}; /// use chrono::naive::serde::ts_seconds_option; /// #[derive(Deserialize, Serialize)] /// struct S { @@ -1140,7 +925,6 @@ pub mod ts_seconds { /// time: Option /// } /// -/// # fn example() -> Result { /// let time = Some(NaiveDate::from_ymd(2018, 5, 17).and_hms(02, 04, 59)); /// let my_s = S { /// time: time.clone(), @@ -1150,9 +934,7 @@ pub mod ts_seconds { /// assert_eq!(as_string, r#"{"time":1526522699}"#); /// let my_s: S = serde_json::from_str(&as_string)?; /// assert_eq!(my_s.time, time); -/// # Ok(my_s) -/// # } -/// # fn main() { example().unwrap(); } +/// # Ok::<(), serde_json::Error>(()) /// ``` pub mod ts_seconds_option { use core::fmt; @@ -1168,14 +950,8 @@ pub mod ts_seconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::naive::{NaiveDate, NaiveDateTime}; + /// # use serde_derive::Serialize; /// use chrono::naive::serde::ts_seconds_option::serialize as to_tsopt; /// #[derive(Serialize)] /// struct S { @@ -1183,15 +959,12 @@ pub mod ts_seconds_option { /// time: Option /// } /// - /// # fn example() -> Result { /// let my_s = S { /// time: Some(NaiveDate::from_ymd(2018, 5, 17).and_hms(02, 04, 59)), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699}"#); - /// # Ok(as_string) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn serialize(opt: &Option, serializer: S) -> Result where @@ -1210,14 +983,8 @@ pub mod ts_seconds_option { /// # Example: /// /// ```rust - /// # // We mark this ignored so that we can test on 1.13 (which does not - /// # // support custom derive), and run tests with --ignored on beta and - /// # // nightly to actually trigger these. - /// # - /// # #[macro_use] extern crate serde_derive; - /// # #[macro_use] extern crate serde_json; - /// # extern crate chrono; /// # use chrono::naive::{NaiveDate, NaiveDateTime}; + /// # use serde_derive::Deserialize; /// use chrono::naive::serde::ts_seconds_option::deserialize as from_tsopt; /// #[derive(Deserialize)] /// struct S { @@ -1225,11 +992,8 @@ pub mod ts_seconds_option { /// time: Option /// } /// - /// # fn example() -> Result { /// let my_s: S = serde_json::from_str(r#"{ "time": 1431684000 }"#)?; - /// # Ok(my_s) - /// # } - /// # fn main() { example().unwrap(); } + /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result, D::Error> where diff --git a/src/naive/time/mod.rs b/src/naive/time/mod.rs index 29b0929a06..1bcfd03a3a 100644 --- a/src/naive/time/mod.rs +++ b/src/naive/time/mod.rs @@ -529,7 +529,6 @@ impl NaiveTime { /// # Example /// /// ``` - /// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveTime}; /// /// let from_hms = NaiveTime::from_hms; @@ -540,7 +539,6 @@ impl NaiveTime { /// (from_hms(2, 4, 5), 86_400)); /// assert_eq!(from_hms(3, 4, 5).overflowing_add_signed(Duration::hours(-7)), /// (from_hms(20, 4, 5), -86_400)); - /// # } /// ``` #[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] pub fn overflowing_add_signed(&self, mut rhs: OldDuration) -> (NaiveTime, i64) { @@ -614,7 +612,6 @@ impl NaiveTime { /// # Example /// /// ``` - /// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveTime}; /// /// let from_hms = NaiveTime::from_hms; @@ -625,7 +622,6 @@ impl NaiveTime { /// (from_hms(10, 4, 5), 86_400)); /// assert_eq!(from_hms(3, 4, 5).overflowing_sub_signed(Duration::hours(-22)), /// (from_hms(1, 4, 5), -86_400)); - /// # } /// ``` #[inline] pub fn overflowing_sub_signed(&self, rhs: OldDuration) -> (NaiveTime, i64) { @@ -646,7 +642,6 @@ impl NaiveTime { /// # Example /// /// ``` - /// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveTime}; /// /// let from_hmsm = NaiveTime::from_hms_milli; @@ -668,14 +663,12 @@ impl NaiveTime { /// Duration::seconds(-3600)); /// assert_eq!(since(from_hmsm(3, 5, 7, 900), from_hmsm(2, 4, 6, 800)), /// Duration::seconds(3600 + 60 + 1) + Duration::milliseconds(100)); - /// # } /// ``` /// /// Leap seconds are handled, but the subtraction assumes that /// there were no other leap seconds happened. /// /// ``` - /// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveTime}; /// # let from_hmsm = NaiveTime::from_hms_milli; /// # let since = NaiveTime::signed_duration_since; @@ -689,7 +682,6 @@ impl NaiveTime { /// Duration::seconds(1)); /// assert_eq!(since(from_hmsm(3, 0, 59, 1_000), from_hmsm(2, 59, 59, 1_000)), /// Duration::seconds(61)); - /// # } /// ``` pub fn signed_duration_since(self, rhs: NaiveTime) -> OldDuration { // | | :leap| | | | | | | :leap| | @@ -1034,7 +1026,6 @@ impl Timelike for NaiveTime { /// # Example /// /// ``` -/// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveTime}; /// /// let from_hmsm = NaiveTime::from_hms_milli; @@ -1047,25 +1038,21 @@ impl Timelike for NaiveTime { /// assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::milliseconds(80), from_hmsm(3, 5, 7, 80)); /// assert_eq!(from_hmsm(3, 5, 7, 950) + Duration::milliseconds(280), from_hmsm(3, 5, 8, 230)); /// assert_eq!(from_hmsm(3, 5, 7, 950) + Duration::milliseconds(-980), from_hmsm(3, 5, 6, 970)); -/// # } /// ``` /// /// The addition wraps around. /// /// ``` -/// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveTime}; /// # let from_hmsm = NaiveTime::from_hms_milli; /// assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::seconds(22*60*60), from_hmsm(1, 5, 7, 0)); /// assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::seconds(-8*60*60), from_hmsm(19, 5, 7, 0)); /// assert_eq!(from_hmsm(3, 5, 7, 0) + Duration::days(800), from_hmsm(3, 5, 7, 0)); -/// # } /// ``` /// /// Leap seconds are handled, but the addition assumes that it is the only leap second happened. /// /// ``` -/// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveTime}; /// # let from_hmsm = NaiveTime::from_hms_milli; /// let leap = from_hmsm(3, 5, 59, 1_300); @@ -1076,7 +1063,6 @@ impl Timelike for NaiveTime { /// assert_eq!(leap + Duration::seconds(10), from_hmsm(3, 6, 9, 300)); /// assert_eq!(leap + Duration::seconds(-10), from_hmsm(3, 5, 50, 300)); /// assert_eq!(leap + Duration::days(1), from_hmsm(3, 5, 59, 300)); -/// # } /// ``` impl Add for NaiveTime { type Output = NaiveTime; @@ -1106,7 +1092,6 @@ impl AddAssign for NaiveTime { /// # Example /// /// ``` -/// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveTime}; /// /// let from_hmsm = NaiveTime::from_hms_milli; @@ -1117,24 +1102,20 @@ impl AddAssign for NaiveTime { /// assert_eq!(from_hmsm(3, 5, 7, 0) - Duration::seconds(2*60*60 + 6*60), from_hmsm(0, 59, 7, 0)); /// assert_eq!(from_hmsm(3, 5, 7, 0) - Duration::milliseconds(80), from_hmsm(3, 5, 6, 920)); /// assert_eq!(from_hmsm(3, 5, 7, 950) - Duration::milliseconds(280), from_hmsm(3, 5, 7, 670)); -/// # } /// ``` /// /// The subtraction wraps around. /// /// ``` -/// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveTime}; /// # let from_hmsm = NaiveTime::from_hms_milli; /// assert_eq!(from_hmsm(3, 5, 7, 0) - Duration::seconds(8*60*60), from_hmsm(19, 5, 7, 0)); /// assert_eq!(from_hmsm(3, 5, 7, 0) - Duration::days(800), from_hmsm(3, 5, 7, 0)); -/// # } /// ``` /// /// Leap seconds are handled, but the subtraction assumes that it is the only leap second happened. /// /// ``` -/// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveTime}; /// # let from_hmsm = NaiveTime::from_hms_milli; /// let leap = from_hmsm(3, 5, 59, 1_300); @@ -1143,7 +1124,6 @@ impl AddAssign for NaiveTime { /// assert_eq!(leap - Duration::milliseconds(500), from_hmsm(3, 5, 59, 800)); /// assert_eq!(leap - Duration::seconds(60), from_hmsm(3, 5, 0, 300)); /// assert_eq!(leap - Duration::days(1), from_hmsm(3, 6, 0, 300)); -/// # } /// ``` impl Sub for NaiveTime { type Output = NaiveTime; @@ -1177,7 +1157,6 @@ impl SubAssign for NaiveTime { /// # Example /// /// ``` -/// # extern crate chrono; fn main() { /// use chrono::{Duration, NaiveTime}; /// /// let from_hmsm = NaiveTime::from_hms_milli; @@ -1191,14 +1170,12 @@ impl SubAssign for NaiveTime { /// assert_eq!(from_hmsm(3, 5, 7, 900) - from_hmsm(4, 5, 7, 900), Duration::seconds(-3600)); /// assert_eq!(from_hmsm(3, 5, 7, 900) - from_hmsm(2, 4, 6, 800), /// Duration::seconds(3600 + 60 + 1) + Duration::milliseconds(100)); -/// # } /// ``` /// /// Leap seconds are handled, but the subtraction assumes that /// there were no other leap seconds happened. /// /// ``` -/// # extern crate chrono; fn main() { /// # use chrono::{Duration, NaiveTime}; /// # let from_hmsm = NaiveTime::from_hms_milli; /// assert_eq!(from_hmsm(3, 0, 59, 1_000) - from_hmsm(3, 0, 59, 0), Duration::seconds(1)); @@ -1208,7 +1185,6 @@ impl SubAssign for NaiveTime { /// assert_eq!(from_hmsm(3, 0, 0, 0) - from_hmsm(2, 59, 59, 1_000), Duration::seconds(1)); /// assert_eq!(from_hmsm(3, 0, 59, 1_000) - from_hmsm(2, 59, 59, 1_000), /// Duration::seconds(61)); -/// # } /// ``` impl Sub for NaiveTime { type Output = OldDuration;