update for serde 0.9

This commit is contained in:
Ashley Mannix 2017-01-28 15:19:12 +10:00
parent ae7fddc215
commit 898e266e02
5 changed files with 41 additions and 17 deletions

View File

@ -18,8 +18,8 @@ name = "chrono"
time = "0.1" time = "0.1"
num = { version = "0.1", default-features = false } num = { version = "0.1", default-features = false }
rustc-serialize = { version = "0.3", optional = true } rustc-serialize = { version = "0.3", optional = true }
serde = { version = "<0.9", optional = true } serde = { version = "0.9", optional = true }
[dev-dependencies] [dev-dependencies]
serde_json = { version = ">=0.7.0" } serde_json = { version = ">=0.9.0" }
bincode = { version = "0.6", features = ["serde"], default-features = false } bincode = { version = "1.0.0-alpha1", features = ["serde"], default-features = false }

View File

@ -472,6 +472,7 @@ mod rustc_serialize {
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
mod serde { mod serde {
use std::fmt;
use super::DateTime; use super::DateTime;
use offset::TimeZone; use offset::TimeZone;
use offset::utc::UTC; use offset::utc::UTC;
@ -485,7 +486,7 @@ mod serde {
impl<Tz: TimeZone> ser::Serialize for DateTime<Tz> impl<Tz: TimeZone> ser::Serialize for DateTime<Tz>
where Tz::Offset: Display where Tz::Offset: Display
{ {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: ser::Serializer where S: ser::Serializer
{ {
// Debug formatting is correct RFC3339, and it allows Zulu. // Debug formatting is correct RFC3339, and it allows Zulu.
@ -498,7 +499,12 @@ mod serde {
impl de::Visitor for DateTimeVisitor { impl de::Visitor for DateTimeVisitor {
type Value = DateTime<FixedOffset>; type Value = DateTime<FixedOffset>;
fn visit_str<E>(&mut self, value: &str) -> Result<DateTime<FixedOffset>, E> fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result
{
write!(formatter, "a formatted date and time string")
}
fn visit_str<E>(self, value: &str) -> Result<DateTime<FixedOffset>, E>
where E: de::Error where E: de::Error
{ {
value.parse().map_err(|err| E::custom(format!("{}", err))) value.parse().map_err(|err| E::custom(format!("{}", err)))
@ -506,7 +512,7 @@ mod serde {
} }
impl de::Deserialize for DateTime<FixedOffset> { impl de::Deserialize for DateTime<FixedOffset> {
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: de::Deserializer where D: de::Deserializer
{ {
deserializer.deserialize_str(DateTimeVisitor) deserializer.deserialize_str(DateTimeVisitor)
@ -514,7 +520,7 @@ mod serde {
} }
impl de::Deserialize for DateTime<UTC> { impl de::Deserialize for DateTime<UTC> {
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: de::Deserializer where D: de::Deserializer
{ {
deserializer.deserialize_str(DateTimeVisitor).map(|dt| dt.with_timezone(&UTC)) deserializer.deserialize_str(DateTimeVisitor).map(|dt| dt.with_timezone(&UTC))
@ -522,7 +528,7 @@ mod serde {
} }
impl de::Deserialize for DateTime<Local> { impl de::Deserialize for DateTime<Local> {
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: de::Deserializer where D: de::Deserializer
{ {
deserializer.deserialize_str(DateTimeVisitor).map(|dt| dt.with_timezone(&Local)) deserializer.deserialize_str(DateTimeVisitor).map(|dt| dt.with_timezone(&Local))

View File

@ -1562,13 +1562,14 @@ mod rustc_serialize {
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
mod serde { mod serde {
use std::fmt;
use super::NaiveDate; use super::NaiveDate;
use serde::{ser, de}; use serde::{ser, de};
// TODO not very optimized for space (binary formats would want something better) // TODO not very optimized for space (binary formats would want something better)
impl ser::Serialize for NaiveDate { impl ser::Serialize for NaiveDate {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: ser::Serializer where S: ser::Serializer
{ {
serializer.serialize_str(&format!("{:?}", self)) serializer.serialize_str(&format!("{:?}", self))
@ -1580,7 +1581,12 @@ mod serde {
impl de::Visitor for NaiveDateVisitor { impl de::Visitor for NaiveDateVisitor {
type Value = NaiveDate; type Value = NaiveDate;
fn visit_str<E>(&mut self, value: &str) -> Result<NaiveDate, E> fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result
{
write!(formatter, "a formatted date string")
}
fn visit_str<E>(self, value: &str) -> Result<NaiveDate, E>
where E: de::Error where E: de::Error
{ {
value.parse().map_err(|err| E::custom(format!("{}", err))) value.parse().map_err(|err| E::custom(format!("{}", err)))
@ -1588,7 +1594,7 @@ mod serde {
} }
impl de::Deserialize for NaiveDate { impl de::Deserialize for NaiveDate {
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: de::Deserializer where D: de::Deserializer
{ {
deserializer.deserialize_str(NaiveDateVisitor) deserializer.deserialize_str(NaiveDateVisitor)

View File

@ -1416,13 +1416,14 @@ mod rustc_serialize {
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
mod serde { mod serde {
use std::fmt;
use super::NaiveDateTime; use super::NaiveDateTime;
use serde::{ser, de}; use serde::{ser, de};
// TODO not very optimized for space (binary formats would want something better) // TODO not very optimized for space (binary formats would want something better)
impl ser::Serialize for NaiveDateTime { impl ser::Serialize for NaiveDateTime {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: ser::Serializer where S: ser::Serializer
{ {
serializer.serialize_str(&format!("{:?}", self)) serializer.serialize_str(&format!("{:?}", self))
@ -1434,7 +1435,12 @@ mod serde {
impl de::Visitor for NaiveDateTimeVisitor { impl de::Visitor for NaiveDateTimeVisitor {
type Value = NaiveDateTime; type Value = NaiveDateTime;
fn visit_str<E>(&mut self, value: &str) -> Result<NaiveDateTime, E> fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result
{
write!(formatter, "a formatted date and time string")
}
fn visit_str<E>(self, value: &str) -> Result<NaiveDateTime, E>
where E: de::Error where E: de::Error
{ {
value.parse().map_err(|err| E::custom(format!("{}", err))) value.parse().map_err(|err| E::custom(format!("{}", err)))
@ -1442,7 +1448,7 @@ mod serde {
} }
impl de::Deserialize for NaiveDateTime { impl de::Deserialize for NaiveDateTime {
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: de::Deserializer where D: de::Deserializer
{ {
deserializer.deserialize_str(NaiveDateTimeVisitor) deserializer.deserialize_str(NaiveDateTimeVisitor)

View File

@ -1309,6 +1309,7 @@ mod rustc_serialize {
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
mod serde { mod serde {
use std::fmt;
use super::NaiveTime; use super::NaiveTime;
use serde::{ser, de}; use serde::{ser, de};
@ -1316,7 +1317,7 @@ mod serde {
// TODO round-trip for general leap seconds (not just those with second = 60) // TODO round-trip for general leap seconds (not just those with second = 60)
impl ser::Serialize for NaiveTime { impl ser::Serialize for NaiveTime {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: ser::Serializer where S: ser::Serializer
{ {
serializer.serialize_str(&format!("{:?}", self)) serializer.serialize_str(&format!("{:?}", self))
@ -1328,7 +1329,12 @@ mod serde {
impl de::Visitor for NaiveTimeVisitor { impl de::Visitor for NaiveTimeVisitor {
type Value = NaiveTime; type Value = NaiveTime;
fn visit_str<E>(&mut self, value: &str) -> Result<NaiveTime, E> fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result
{
write!(formatter, "a formatted time string")
}
fn visit_str<E>(self, value: &str) -> Result<NaiveTime, E>
where E: de::Error where E: de::Error
{ {
value.parse().map_err(|err| E::custom(format!("{}", err))) value.parse().map_err(|err| E::custom(format!("{}", err)))
@ -1336,7 +1342,7 @@ mod serde {
} }
impl de::Deserialize for NaiveTime { impl de::Deserialize for NaiveTime {
fn deserialize<D>(deserializer: &mut D) -> Result<Self, D::Error> fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: de::Deserializer where D: de::Deserializer
{ {
deserializer.deserialize_str(NaiveTimeVisitor) deserializer.deserialize_str(NaiveTimeVisitor)