From 898e266e025fb6052fd01d8b48481aa327f27d86 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sat, 28 Jan 2017 15:19:12 +1000 Subject: [PATCH 1/3] update for serde 0.9 --- Cargo.toml | 6 +++--- src/datetime.rs | 16 +++++++++++----- src/naive/date.rs | 12 +++++++++--- src/naive/datetime.rs | 12 +++++++++--- src/naive/time.rs | 12 +++++++++--- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 364e575..9332886 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,8 @@ name = "chrono" time = "0.1" num = { version = "0.1", default-features = false } rustc-serialize = { version = "0.3", optional = true } -serde = { version = "<0.9", optional = true } +serde = { version = "0.9", optional = true } [dev-dependencies] -serde_json = { version = ">=0.7.0" } -bincode = { version = "0.6", features = ["serde"], default-features = false } +serde_json = { version = ">=0.9.0" } +bincode = { version = "1.0.0-alpha1", features = ["serde"], default-features = false } diff --git a/src/datetime.rs b/src/datetime.rs index 55b69fd..15170ec 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -472,6 +472,7 @@ mod rustc_serialize { #[cfg(feature = "serde")] mod serde { + use std::fmt; use super::DateTime; use offset::TimeZone; use offset::utc::UTC; @@ -485,7 +486,7 @@ mod serde { impl ser::Serialize for DateTime where Tz::Offset: Display { - fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> + fn serialize(&self, serializer: S) -> Result where S: ser::Serializer { // Debug formatting is correct RFC3339, and it allows Zulu. @@ -498,7 +499,12 @@ mod serde { impl de::Visitor for DateTimeVisitor { type Value = DateTime; - fn visit_str(&mut self, value: &str) -> Result, E> + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result + { + write!(formatter, "a formatted date and time string") + } + + fn visit_str(self, value: &str) -> Result, E> where E: de::Error { value.parse().map_err(|err| E::custom(format!("{}", err))) @@ -506,7 +512,7 @@ mod serde { } impl de::Deserialize for DateTime { - fn deserialize(deserializer: &mut D) -> Result + fn deserialize(deserializer: D) -> Result where D: de::Deserializer { deserializer.deserialize_str(DateTimeVisitor) @@ -514,7 +520,7 @@ mod serde { } impl de::Deserialize for DateTime { - fn deserialize(deserializer: &mut D) -> Result + fn deserialize(deserializer: D) -> Result where D: de::Deserializer { deserializer.deserialize_str(DateTimeVisitor).map(|dt| dt.with_timezone(&UTC)) @@ -522,7 +528,7 @@ mod serde { } impl de::Deserialize for DateTime { - fn deserialize(deserializer: &mut D) -> Result + fn deserialize(deserializer: D) -> Result where D: de::Deserializer { deserializer.deserialize_str(DateTimeVisitor).map(|dt| dt.with_timezone(&Local)) diff --git a/src/naive/date.rs b/src/naive/date.rs index 85cde84..591c249 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -1562,13 +1562,14 @@ mod rustc_serialize { #[cfg(feature = "serde")] mod serde { + use std::fmt; use super::NaiveDate; use serde::{ser, de}; // TODO not very optimized for space (binary formats would want something better) impl ser::Serialize for NaiveDate { - fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> + fn serialize(&self, serializer: S) -> Result where S: ser::Serializer { serializer.serialize_str(&format!("{:?}", self)) @@ -1580,7 +1581,12 @@ mod serde { impl de::Visitor for NaiveDateVisitor { type Value = NaiveDate; - fn visit_str(&mut self, value: &str) -> Result + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result + { + write!(formatter, "a formatted date string") + } + + fn visit_str(self, value: &str) -> Result where E: de::Error { value.parse().map_err(|err| E::custom(format!("{}", err))) @@ -1588,7 +1594,7 @@ mod serde { } impl de::Deserialize for NaiveDate { - fn deserialize(deserializer: &mut D) -> Result + fn deserialize(deserializer: D) -> Result where D: de::Deserializer { deserializer.deserialize_str(NaiveDateVisitor) diff --git a/src/naive/datetime.rs b/src/naive/datetime.rs index 2beadee..e14f1fa 100644 --- a/src/naive/datetime.rs +++ b/src/naive/datetime.rs @@ -1416,13 +1416,14 @@ mod rustc_serialize { #[cfg(feature = "serde")] mod serde { + use std::fmt; use super::NaiveDateTime; use serde::{ser, de}; // TODO not very optimized for space (binary formats would want something better) impl ser::Serialize for NaiveDateTime { - fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> + fn serialize(&self, serializer: S) -> Result where S: ser::Serializer { serializer.serialize_str(&format!("{:?}", self)) @@ -1434,7 +1435,12 @@ mod serde { impl de::Visitor for NaiveDateTimeVisitor { type Value = NaiveDateTime; - fn visit_str(&mut self, value: &str) -> Result + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result + { + write!(formatter, "a formatted date and time string") + } + + fn visit_str(self, value: &str) -> Result where E: de::Error { value.parse().map_err(|err| E::custom(format!("{}", err))) @@ -1442,7 +1448,7 @@ mod serde { } impl de::Deserialize for NaiveDateTime { - fn deserialize(deserializer: &mut D) -> Result + fn deserialize(deserializer: D) -> Result where D: de::Deserializer { deserializer.deserialize_str(NaiveDateTimeVisitor) diff --git a/src/naive/time.rs b/src/naive/time.rs index ec8f564..2765951 100644 --- a/src/naive/time.rs +++ b/src/naive/time.rs @@ -1309,6 +1309,7 @@ mod rustc_serialize { #[cfg(feature = "serde")] mod serde { + use std::fmt; use super::NaiveTime; use serde::{ser, de}; @@ -1316,7 +1317,7 @@ mod serde { // TODO round-trip for general leap seconds (not just those with second = 60) impl ser::Serialize for NaiveTime { - fn serialize(&self, serializer: &mut S) -> Result<(), S::Error> + fn serialize(&self, serializer: S) -> Result where S: ser::Serializer { serializer.serialize_str(&format!("{:?}", self)) @@ -1328,7 +1329,12 @@ mod serde { impl de::Visitor for NaiveTimeVisitor { type Value = NaiveTime; - fn visit_str(&mut self, value: &str) -> Result + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result + { + write!(formatter, "a formatted time string") + } + + fn visit_str(self, value: &str) -> Result where E: de::Error { value.parse().map_err(|err| E::custom(format!("{}", err))) @@ -1336,7 +1342,7 @@ mod serde { } impl de::Deserialize for NaiveTime { - fn deserialize(deserializer: &mut D) -> Result + fn deserialize(deserializer: D) -> Result where D: de::Deserializer { deserializer.deserialize_str(NaiveTimeVisitor) From 66198fbb2e145598a092ae383ab01d4eca20456e Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 3 Feb 2017 17:30:17 +1000 Subject: [PATCH 2/3] set min version to 1.13 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f683dc7..76d570c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ sudo: false rust: # 1.8.0 is the earliest known version that Cargo does work for the current crates.io-index repo. # probably older versions work, but we are forced to use this as the minimum for Cargo... - - 1.8.0 + - 1.13.0 - stable - beta - nightly From 7ed6caa4119776fbf008c98da1073fa4d282390b Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Fri, 3 Feb 2017 18:00:52 +1000 Subject: [PATCH 3/3] set min version to 1.13 --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index f682bb4..241d049 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ environment: matrix: - - TARGET: 1.8.0-x86_64-pc-windows-gnu + - TARGET: 1.13.0-x86_64-pc-windows-gnu - TARGET: nightly-x86_64-pc-windows-msvc - TARGET: nightly-i686-pc-windows-msvc - TARGET: nightly-x86_64-pc-windows-gnu