Merge pull request #142 from KodrAus/feat/serde-1.0
Upgrade to serde 1.0
This commit is contained in:
commit
62195bea6f
|
@ -23,8 +23,8 @@ name = "chrono"
|
|||
time = "^0.1.36"
|
||||
num = { version = "0.1", default-features = false }
|
||||
rustc-serialize = { version = "0.3", optional = true }
|
||||
serde = { version = "0.9", optional = true }
|
||||
serde = { version = "1", optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = { version = ">=0.9.0" }
|
||||
bincode = { version = "1.0.0-alpha6", features = ["serde"], default-features = false }
|
||||
serde_json = { version = "1" }
|
||||
bincode = { version = "0.7.0", features = ["serde"], default-features = false, git = "https://github.com/TyOverby/bincode.git" }
|
||||
|
|
|
@ -416,8 +416,8 @@ fn test_encodable_json<FUTC, FFixed, E>(to_string_utc: FUTC, to_string_fixed: FF
|
|||
|
||||
#[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
|
||||
fn test_decodable_json<FUTC, FFixed, FLocal, E>(utc_from_str: FUTC,
|
||||
fixed_from_str: FFixed,
|
||||
local_from_str: FLocal)
|
||||
fixed_from_str: FFixed,
|
||||
local_from_str: FLocal)
|
||||
where FUTC: Fn(&str) -> Result<DateTime<UTC>, E>,
|
||||
FFixed: Fn(&str) -> Result<DateTime<FixedOffset>, E>,
|
||||
FLocal: Fn(&str) -> Result<DateTime<Local>, E>,
|
||||
|
@ -520,14 +520,24 @@ mod serde {
|
|||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: ser::Serializer
|
||||
{
|
||||
struct FormatWrapped<'a, D: 'a> {
|
||||
inner: &'a D
|
||||
}
|
||||
|
||||
impl<'a, D: fmt::Debug> fmt::Display for FormatWrapped<'a, D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.inner.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
// Debug formatting is correct RFC3339, and it allows Zulu.
|
||||
serializer.serialize_str(&format!("{:?}", self))
|
||||
serializer.collect_str(&FormatWrapped { inner: &self })
|
||||
}
|
||||
}
|
||||
|
||||
struct DateTimeVisitor;
|
||||
|
||||
impl de::Visitor for DateTimeVisitor {
|
||||
impl<'de> de::Visitor<'de> for DateTimeVisitor {
|
||||
type Value = DateTime<FixedOffset>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result
|
||||
|
@ -542,25 +552,25 @@ mod serde {
|
|||
}
|
||||
}
|
||||
|
||||
impl de::Deserialize for DateTime<FixedOffset> {
|
||||
impl<'de> de::Deserialize<'de> for DateTime<FixedOffset> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: de::Deserializer
|
||||
where D: de::Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_str(DateTimeVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
impl de::Deserialize for DateTime<UTC> {
|
||||
impl<'de> de::Deserialize<'de> for DateTime<UTC> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: de::Deserializer
|
||||
where D: de::Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_str(DateTimeVisitor).map(|dt| dt.with_timezone(&UTC))
|
||||
}
|
||||
}
|
||||
|
||||
impl de::Deserialize for DateTime<Local> {
|
||||
impl<'de> de::Deserialize<'de> for DateTime<Local> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: de::Deserializer
|
||||
where D: de::Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_str(DateTimeVisitor).map(|dt| dt.with_timezone(&Local))
|
||||
}
|
||||
|
@ -576,8 +586,8 @@ mod serde {
|
|||
|
||||
#[test]
|
||||
fn test_serde_deserialize() {
|
||||
super::test_decodable_json(self::serde_json::from_str, self::serde_json::from_str,
|
||||
self::serde_json::from_str);
|
||||
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));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1570,13 +1570,23 @@ mod serde {
|
|||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: ser::Serializer
|
||||
{
|
||||
serializer.serialize_str(&format!("{:?}", self))
|
||||
struct FormatWrapped<'a, D: 'a> {
|
||||
inner: &'a D
|
||||
}
|
||||
|
||||
impl<'a, D: fmt::Debug> fmt::Display for FormatWrapped<'a, D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.inner.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
serializer.collect_str(&FormatWrapped { inner: &self })
|
||||
}
|
||||
}
|
||||
|
||||
struct NaiveDateVisitor;
|
||||
|
||||
impl de::Visitor for NaiveDateVisitor {
|
||||
impl<'de> de::Visitor<'de> for NaiveDateVisitor {
|
||||
type Value = NaiveDate;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result
|
||||
|
@ -1591,9 +1601,9 @@ mod serde {
|
|||
}
|
||||
}
|
||||
|
||||
impl de::Deserialize for NaiveDate {
|
||||
impl<'de> de::Deserialize<'de> for NaiveDate {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: de::Deserializer
|
||||
where D: de::Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_str(NaiveDateVisitor)
|
||||
}
|
||||
|
@ -1609,7 +1619,7 @@ mod serde {
|
|||
|
||||
#[test]
|
||||
fn test_serde_deserialize() {
|
||||
super::test_decodable_json(self::serde_json::from_str);
|
||||
super::test_decodable_json(|input| self::serde_json::from_str(&input));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1468,13 +1468,23 @@ mod serde {
|
|||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: ser::Serializer
|
||||
{
|
||||
serializer.serialize_str(&format!("{:?}", self))
|
||||
struct FormatWrapped<'a, D: 'a> {
|
||||
inner: &'a D
|
||||
}
|
||||
|
||||
impl<'a, D: fmt::Debug> fmt::Display for FormatWrapped<'a, D> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.inner.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
serializer.collect_str(&FormatWrapped { inner: &self })
|
||||
}
|
||||
}
|
||||
|
||||
struct NaiveDateTimeVisitor;
|
||||
|
||||
impl de::Visitor for NaiveDateTimeVisitor {
|
||||
impl<'de> de::Visitor<'de> for NaiveDateTimeVisitor {
|
||||
type Value = NaiveDateTime;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result
|
||||
|
@ -1489,9 +1499,9 @@ mod serde {
|
|||
}
|
||||
}
|
||||
|
||||
impl de::Deserialize for NaiveDateTime {
|
||||
impl<'de> de::Deserialize<'de> for NaiveDateTime {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: de::Deserializer
|
||||
where D: de::Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_str(NaiveDateTimeVisitor)
|
||||
}
|
||||
|
@ -1507,7 +1517,7 @@ mod serde {
|
|||
|
||||
#[test]
|
||||
fn test_serde_deserialize() {
|
||||
super::test_decodable_json(self::serde_json::from_str);
|
||||
super::test_decodable_json(|input| self::serde_json::from_str(&input));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1346,13 +1346,13 @@ mod serde {
|
|||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where S: ser::Serializer
|
||||
{
|
||||
serializer.serialize_str(&format!("{:?}", self))
|
||||
serializer.collect_str(&self)
|
||||
}
|
||||
}
|
||||
|
||||
struct NaiveTimeVisitor;
|
||||
|
||||
impl de::Visitor for NaiveTimeVisitor {
|
||||
impl<'de> de::Visitor<'de> for NaiveTimeVisitor {
|
||||
type Value = NaiveTime;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result
|
||||
|
@ -1367,9 +1367,9 @@ mod serde {
|
|||
}
|
||||
}
|
||||
|
||||
impl de::Deserialize for NaiveTime {
|
||||
impl<'de> de::Deserialize<'de> for NaiveTime {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where D: de::Deserializer
|
||||
where D: de::Deserializer<'de>
|
||||
{
|
||||
deserializer.deserialize_str(NaiveTimeVisitor)
|
||||
}
|
||||
|
@ -1385,7 +1385,7 @@ mod serde {
|
|||
|
||||
#[test]
|
||||
fn test_serde_deserialize() {
|
||||
super::test_decodable_json(self::serde_json::from_str);
|
||||
super::test_decodable_json(|input| self::serde_json::from_str(&input));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue