Remove rustc-serialize from library

This commit is contained in:
Jubilee Young 2024-03-29 21:02:24 -07:00 committed by Paul Dicker
parent 7d62045ec4
commit 6c86cd1560
16 changed files with 18 additions and 364 deletions

View File

@ -2,7 +2,7 @@ name: codecov
env:
# It's really `--all-features`, but not adding the mutually exclusive features from rkyv
ALL_NON_EXCLUSIVE_FEATURES: --features "default unstable-locales rkyv-64 rkyv-validation rustc-serialize serde arbitrary"
ALL_NON_EXCLUSIVE_FEATURES: --features "default unstable-locales rkyv-64 rkyv-validation serde arbitrary"
on:
push:

View File

@ -2,7 +2,7 @@ name: lint
env:
# It's really `--all-features`, but not adding the mutually exclusive features from rkyv
ALL_NON_EXCLUSIVE_FEATURES: --features "default unstable-locales rkyv-64 rkyv-validation rustc-serialize serde arbitrary"
ALL_NON_EXCLUSIVE_FEATURES: --features "default unstable-locales rkyv-64 rkyv-validation serde arbitrary"
on:
push:

View File

@ -2,7 +2,7 @@ name: All Tests and Builds
env:
# It's really `--all-features`, but not adding the mutually exclusive features from rkyv
ALL_NON_EXCLUSIVE_FEATURES: --features "default unstable-locales rkyv-32 rkyv-validation rustc-serialize serde arbitrary"
ALL_NON_EXCLUSIVE_FEATURES: --features "default unstable-locales rkyv-32 rkyv-validation serde arbitrary"
on:
push:
@ -41,12 +41,12 @@ jobs:
- run: |
cargo test --lib \
--features \
unstable-locales,wasmbind,oldtime,clock,rustc-serialize,winapi,serde \
unstable-locales,wasmbind,oldtime,clock,winapi,serde \
--color=always -- --color=always
- run: |
cargo test --doc \
--features \
unstable-locales,wasmbind,oldtime,clock,rustc-serialize,winapi,serde \
unstable-locales,wasmbind,oldtime,clock,winapi,serde \
--color=always -- --color=always
rust_versions:

View File

@ -34,9 +34,6 @@ use crate::{Datelike, Months, TimeDelta, Timelike, Weekday};
#[cfg(any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"))]
use rkyv::{Archive, Deserialize, Serialize};
#[cfg(feature = "rustc-serialize")]
pub(super) mod rustc_serialize;
/// documented at re-export site
#[cfg(feature = "serde")]
pub(super) mod serde;
@ -1937,7 +1934,7 @@ where
/// 719163
const UNIX_EPOCH_DAY: i64 = 719_163;
#[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
#[cfg(all(test, feature = "serde"))]
fn test_encodable_json<FUtc, FFixed, E>(to_string_utc: FUtc, to_string_fixed: FFixed)
where
FUtc: Fn(&DateTime<Utc>) -> Result<String, E>,
@ -1967,7 +1964,7 @@ where
);
}
#[cfg(all(test, feature = "clock", any(feature = "rustc-serialize", feature = "serde")))]
#[cfg(all(test, feature = "clock", feature = "serde"))]
fn test_decodable_json<FUtc, FFixed, FLocal, E>(
utc_from_str: FUtc,
fixed_from_str: FFixed,
@ -2022,50 +2019,3 @@ fn test_decodable_json<FUtc, FFixed, FLocal, E>(
assert!(utc_from_str(r#""2014-07-32T12:34:06Z""#).is_err());
assert!(fixed_from_str(r#""2014-07-32T12:34:06Z""#).is_err());
}
#[cfg(all(test, feature = "clock", feature = "rustc-serialize"))]
fn test_decodable_json_timestamps<FUtc, FFixed, FLocal, E>(
utc_from_str: FUtc,
fixed_from_str: FFixed,
local_from_str: FLocal,
) where
FUtc: Fn(&str) -> Result<rustc_serialize::TsSeconds<Utc>, E>,
FFixed: Fn(&str) -> Result<rustc_serialize::TsSeconds<FixedOffset>, E>,
FLocal: Fn(&str) -> Result<rustc_serialize::TsSeconds<Local>, E>,
E: ::core::fmt::Debug,
{
fn norm<Tz: TimeZone>(dt: &Option<DateTime<Tz>>) -> Option<(&DateTime<Tz>, &Tz::Offset)> {
dt.as_ref().map(|dt| (dt, dt.offset()))
}
assert_eq!(
norm(&utc_from_str("0").ok().map(DateTime::from)),
norm(&Some(Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap()))
);
assert_eq!(
norm(&utc_from_str("-1").ok().map(DateTime::from)),
norm(&Some(Utc.with_ymd_and_hms(1969, 12, 31, 23, 59, 59).unwrap()))
);
assert_eq!(
norm(&fixed_from_str("0").ok().map(DateTime::from)),
norm(&Some(
FixedOffset::east_opt(0).unwrap().with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap()
))
);
assert_eq!(
norm(&fixed_from_str("-1").ok().map(DateTime::from)),
norm(&Some(
FixedOffset::east_opt(0).unwrap().with_ymd_and_hms(1969, 12, 31, 23, 59, 59).unwrap()
))
);
assert_eq!(
*fixed_from_str("0").expect("0 timestamp should parse"),
Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap()
);
assert_eq!(
*local_from_str("-1").expect("-1 timestamp should parse"),
Utc.with_ymd_and_hms(1969, 12, 31, 23, 59, 59).unwrap()
);
}

View File

@ -1,124 +0,0 @@
use super::DateTime;
use crate::format::SecondsFormat;
#[cfg(feature = "clock")]
use crate::offset::Local;
use crate::offset::{FixedOffset, MappedLocalTime, TimeZone, Utc};
use core::fmt;
use core::ops::Deref;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
impl<Tz: TimeZone> Encodable for DateTime<Tz> {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
self.to_rfc3339_opts(SecondsFormat::AutoSi, true).encode(s)
}
}
// Function to convert a MappedLocalTime into a serde-ish Result
fn from<T, D>(me: MappedLocalTime<T>, d: &mut D) -> Result<T, D::Error>
where
D: Decoder,
T: fmt::Display,
{
match me {
MappedLocalTime::None => Err(d.error("value is not a legal timestamp")),
MappedLocalTime::Ambiguous(..) => Err(d.error("value is an ambiguous timestamp")),
MappedLocalTime::Single(val) => Ok(val),
}
}
impl Decodable for DateTime<FixedOffset> {
fn decode<D: Decoder>(d: &mut D) -> Result<DateTime<FixedOffset>, D::Error> {
d.read_str()?.parse::<DateTime<FixedOffset>>().map_err(|_| d.error("invalid date and time"))
}
}
#[allow(deprecated)]
impl Decodable for TsSeconds<FixedOffset> {
#[allow(deprecated)]
fn decode<D: Decoder>(d: &mut D) -> Result<TsSeconds<FixedOffset>, D::Error> {
from(FixedOffset::east_opt(0).unwrap().timestamp_opt(d.read_i64()?, 0), d).map(TsSeconds)
}
}
impl Decodable for DateTime<Utc> {
fn decode<D: Decoder>(d: &mut D) -> Result<DateTime<Utc>, D::Error> {
d.read_str()?
.parse::<DateTime<FixedOffset>>()
.map(|dt| dt.with_timezone(&Utc))
.map_err(|_| d.error("invalid date and time"))
}
}
/// A [`DateTime`] that can be deserialized from a timestamp
///
/// A timestamp here is seconds since the epoch
#[derive(Debug)]
pub struct TsSeconds<Tz: TimeZone>(DateTime<Tz>);
#[allow(deprecated)]
impl<Tz: TimeZone> From<TsSeconds<Tz>> for DateTime<Tz> {
/// Pull the inner `DateTime<Tz>` out
#[allow(deprecated)]
fn from(obj: TsSeconds<Tz>) -> DateTime<Tz> {
obj.0
}
}
#[allow(deprecated)]
impl<Tz: TimeZone> Deref for TsSeconds<Tz> {
type Target = DateTime<Tz>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[allow(deprecated)]
impl Decodable for TsSeconds<Utc> {
fn decode<D: Decoder>(d: &mut D) -> Result<TsSeconds<Utc>, D::Error> {
from(Utc.timestamp_opt(d.read_i64()?, 0), d).map(TsSeconds)
}
}
#[cfg(feature = "clock")]
impl Decodable for DateTime<Local> {
fn decode<D: Decoder>(d: &mut D) -> Result<DateTime<Local>, D::Error> {
match d.read_str()?.parse::<DateTime<FixedOffset>>() {
Ok(dt) => Ok(dt.with_timezone(&Local)),
Err(_) => Err(d.error("invalid date and time")),
}
}
}
#[cfg(feature = "clock")]
#[allow(deprecated)]
impl Decodable for TsSeconds<Local> {
#[allow(deprecated)]
fn decode<D: Decoder>(d: &mut D) -> Result<TsSeconds<Local>, D::Error> {
from(Utc.timestamp_opt(d.read_i64()?, 0), d).map(|dt| TsSeconds(dt.with_timezone(&Local)))
}
}
#[cfg(test)]
mod tests {
use crate::datetime::test_encodable_json;
use crate::datetime::{test_decodable_json, test_decodable_json_timestamps};
use rustc_serialize::json;
#[test]
fn test_encodable() {
test_encodable_json(json::encode, json::encode);
}
#[cfg(feature = "clock")]
#[test]
fn test_decodable() {
test_decodable_json(json::decode, json::decode, json::decode);
}
#[cfg(feature = "clock")]
#[test]
fn test_decodable_timestamps() {
test_decodable_json_timestamps(json::decode, json::decode, json::decode);
}
}

View File

@ -13,14 +13,14 @@ use core::fmt::{self, Write};
#[cfg(feature = "alloc")]
use crate::offset::Offset;
#[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))]
#[cfg(any(feature = "alloc", feature = "serde"))]
use crate::{Datelike, FixedOffset, NaiveDateTime, Timelike};
#[cfg(feature = "alloc")]
use crate::{NaiveDate, NaiveTime, Weekday};
#[cfg(feature = "alloc")]
use super::locales;
#[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))]
#[cfg(any(feature = "alloc", feature = "serde"))]
use super::{Colons, OffsetFormat, OffsetPrecision, Pad};
#[cfg(feature = "alloc")]
use super::{Fixed, InternalFixed, InternalInternal, Item, Numeric};
@ -420,7 +420,7 @@ fn format_inner(
}
}
#[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))]
#[cfg(any(feature = "alloc", feature = "serde"))]
impl OffsetFormat {
/// Writes an offset from UTC with the format defined by `self`.
fn format(&self, w: &mut impl Write, off: FixedOffset) -> fmt::Result {
@ -530,7 +530,7 @@ pub enum SecondsFormat {
/// Writes the date, time and offset to the string. same as `%Y-%m-%dT%H:%M:%S%.f%:z`
#[inline]
#[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))]
#[cfg(any(feature = "alloc", feature = "serde"))]
pub(crate) fn write_rfc3339(
w: &mut impl Write,
dt: NaiveDateTime,

View File

@ -57,7 +57,7 @@ pub(crate) mod locales;
pub(crate) use formatting::write_hundreds;
#[cfg(feature = "alloc")]
pub(crate) use formatting::write_rfc2822;
#[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))]
#[cfg(any(feature = "alloc", feature = "serde"))]
pub(crate) use formatting::write_rfc3339;
pub use formatting::SecondsFormat;
#[cfg(feature = "alloc")]

View File

@ -508,9 +508,6 @@
#![warn(unreachable_pub)]
#![deny(clippy::tests_outside_test_module)]
#![cfg_attr(not(any(feature = "std", test)), no_std)]
// can remove this if/when rustc-serialize support is removed
// keeps clippy happy in the meantime
#![cfg_attr(feature = "rustc-serialize", allow(deprecated))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#[cfg(feature = "alloc")]
@ -551,8 +548,6 @@ pub use date::Date;
pub use date::{MAX_DATE, MIN_DATE};
mod datetime;
#[cfg(feature = "rustc-serialize")]
pub use datetime::rustc_serialize::TsSeconds;
pub use datetime::DateTime;
#[allow(deprecated)]
#[doc(no_inline)]

View File

@ -29,7 +29,6 @@ use crate::OutOfRange;
/// Can be Serialized/Deserialized with serde
// Actual implementation is zero-indexed, API intended as 1-indexed for more intuitive behavior.
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash, PartialOrd, Ord)]
#[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))]
#[cfg_attr(
any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),

View File

@ -2387,7 +2387,7 @@ const YEAR_DELTAS: &[u8; 401] = &[
96, 97, 97, 97, 97, // 400+1
];
#[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
#[cfg(all(test, feature = "serde"))]
fn test_encodable_json<F, E>(to_string: F)
where
F: Fn(&NaiveDate) -> Result<String, E>,
@ -2409,7 +2409,7 @@ where
assert_eq!(to_string(&NaiveDate::MAX).ok(), Some(r#""+262142-12-31""#.into()));
}
#[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
#[cfg(all(test, feature = "serde"))]
fn test_decodable_json<F, E>(from_str: F)
where
F: Fn(&str) -> Result<NaiveDate, E>,
@ -2452,40 +2452,6 @@ where
assert!(from_str(r#"null"#).is_err());
}
#[cfg(feature = "rustc-serialize")]
mod rustc_serialize {
use super::NaiveDate;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
impl Encodable for NaiveDate {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
format!("{:?}", self).encode(s)
}
}
impl Decodable for NaiveDate {
fn decode<D: Decoder>(d: &mut D) -> Result<NaiveDate, D::Error> {
d.read_str()?.parse().map_err(|_| d.error("invalid date"))
}
}
#[cfg(test)]
mod tests {
use crate::naive::date::{test_decodable_json, test_encodable_json};
use rustc_serialize::json;
#[test]
fn test_encodable() {
test_encodable_json(json::encode);
}
#[test]
fn test_decodable() {
test_decodable_json(json::decode);
}
}
}
#[cfg(feature = "serde")]
mod serde {
use super::NaiveDate;

View File

@ -24,8 +24,6 @@ use crate::{
expect, try_opt, DateTime, Datelike, FixedOffset, MappedLocalTime, Months, TimeDelta, TimeZone,
Timelike, Weekday,
};
#[cfg(feature = "rustc-serialize")]
pub(super) mod rustc_serialize;
/// Tools to help serializing/deserializing `NaiveDateTime`s
#[cfg(feature = "serde")]
@ -2152,7 +2150,7 @@ impl Default for NaiveDateTime {
}
}
#[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
#[cfg(all(test, feature = "serde"))]
fn test_encodable_json<F, E>(to_string: F)
where
F: Fn(&NaiveDateTime) -> Result<String, E>,
@ -2194,7 +2192,7 @@ where
);
}
#[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
#[cfg(all(test, feature = "serde"))]
fn test_decodable_json<F, E>(from_str: F)
where
F: Fn(&str) -> Result<NaiveDateTime, E>,
@ -2262,21 +2260,3 @@ where
assert!(from_str(r#"{"date":{"ymdf":20},"time":{"secs":0,"frac":0}}"#).is_err());
assert!(from_str(r#"null"#).is_err());
}
#[cfg(all(test, feature = "rustc-serialize"))]
fn test_decodable_json_timestamp<F, E>(from_str: F)
where
F: Fn(&str) -> Result<rustc_serialize::TsSeconds, E>,
E: ::std::fmt::Debug,
{
assert_eq!(
*from_str("0").unwrap(),
NaiveDate::from_ymd_opt(1970, 1, 1).unwrap().and_hms_opt(0, 0, 0).unwrap(),
"should parse integers as timestamps"
);
assert_eq!(
*from_str("-1").unwrap(),
NaiveDate::from_ymd_opt(1969, 12, 31).unwrap().and_hms_opt(23, 59, 59).unwrap(),
"should parse integers as timestamps"
);
}

View File

@ -1,75 +0,0 @@
use super::NaiveDateTime;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use std::ops::Deref;
impl Encodable for NaiveDateTime {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
format!("{:?}", self).encode(s)
}
}
impl Decodable for NaiveDateTime {
fn decode<D: Decoder>(d: &mut D) -> Result<NaiveDateTime, D::Error> {
d.read_str()?.parse().map_err(|_| d.error("invalid date time string"))
}
}
/// A `DateTime` that can be deserialized from a seconds-based timestamp
#[derive(Debug)]
#[deprecated(
since = "1.4.2",
note = "RustcSerialize will be removed before chrono 1.0, use Serde instead"
)]
pub struct TsSeconds(NaiveDateTime);
#[allow(deprecated)]
impl From<TsSeconds> for NaiveDateTime {
/// Pull the internal NaiveDateTime out
#[allow(deprecated)]
fn from(obj: TsSeconds) -> NaiveDateTime {
obj.0
}
}
#[allow(deprecated)]
impl Deref for TsSeconds {
type Target = NaiveDateTime;
#[allow(deprecated)]
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[allow(deprecated)]
impl Decodable for TsSeconds {
#[allow(deprecated)]
fn decode<D: Decoder>(d: &mut D) -> Result<TsSeconds, D::Error> {
Ok(TsSeconds(
NaiveDateTime::from_timestamp_opt(d.read_i64()?, 0)
.ok_or_else(|| d.error("invalid timestamp"))?,
))
}
}
#[cfg(test)]
mod tests {
use crate::naive::datetime::test_encodable_json;
use crate::naive::datetime::{test_decodable_json, test_decodable_json_timestamp};
use rustc_serialize::json;
#[test]
fn test_encodable() {
test_encodable_json(json::encode);
}
#[test]
fn test_decodable() {
test_decodable_json(json::decode);
}
#[test]
fn test_decodable_timestamps() {
test_decodable_json_timestamp(json::decode);
}
}

View File

@ -18,9 +18,6 @@ pub(crate) mod time;
pub use self::date::{NaiveDate, NaiveDateDaysIterator, NaiveDateWeeksIterator};
#[allow(deprecated)]
pub use self::date::{MAX_DATE, MIN_DATE};
#[cfg(feature = "rustc-serialize")]
#[allow(deprecated)]
pub use self::datetime::rustc_serialize::TsSeconds;
#[allow(deprecated)]
pub use self::datetime::{NaiveDateTime, MAX_DATETIME, MIN_DATETIME};
pub use self::isoweek::IsoWeek;

View File

@ -21,9 +21,6 @@ use crate::format::{
use crate::{expect, try_opt};
use crate::{FixedOffset, TimeDelta, Timelike};
#[cfg(feature = "rustc-serialize")]
mod rustc_serialize;
#[cfg(feature = "serde")]
mod serde;
@ -1645,7 +1642,7 @@ impl Default for NaiveTime {
}
}
#[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
#[cfg(all(test, feature = "serde"))]
fn test_encodable_json<F, E>(to_string: F)
where
F: Fn(&NaiveTime) -> Result<String, E>,
@ -1685,7 +1682,7 @@ where
);
}
#[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
#[cfg(all(test, feature = "serde"))]
fn test_decodable_json<F, E>(from_str: F)
where
F: Fn(&str) -> Result<NaiveTime, E>,

View File

@ -1,30 +0,0 @@
use super::NaiveTime;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
impl Encodable for NaiveTime {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
format!("{:?}", self).encode(s)
}
}
impl Decodable for NaiveTime {
fn decode<D: Decoder>(d: &mut D) -> Result<NaiveTime, D::Error> {
d.read_str()?.parse().map_err(|_| d.error("invalid time"))
}
}
#[cfg(test)]
mod tests {
use crate::naive::time::{test_decodable_json, test_encodable_json};
use rustc_serialize::json;
#[test]
fn test_encodable() {
test_encodable_json(json::encode);
}
#[test]
fn test_decodable() {
test_decodable_json(json::decode);
}
}

View File

@ -30,7 +30,6 @@ use crate::OutOfRange;
/// assert_eq!(sunday.pred(), Weekday::Sat);
/// ```
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
#[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))]
#[cfg_attr(
any(feature = "rkyv", feature = "rkyv-16", feature = "rkyv-32", feature = "rkyv-64"),
derive(Archive, Deserialize, Serialize),