Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated warnings in cargo output for rustc-serialize feature #174

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ Chrono obeys the principle of [Semantic Versioning](http://semver.org/).
There were/are numerous minor versions before 1.0 due to the language changes.
Versions with only mechnical changes will be omitted from the following list.

## 0.4.next

* More strongly deprecate RustcSerialize: remove it from documentation unless
the feature is enabled, issue a deprecation warning if the rustc-serialize
feature is enabled (@quodlibetor)

## 0.4.1

### Bug Fixes
Expand Down
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,14 @@ Put this in your `Cargo.toml`:
chrono = "0.4"
```

Or, if you want [Serde](https://github.com/serde-rs/serde) or
[rustc-serialize](https://github.com/rust-lang-nursery/rustc-serialize) support,
include the features like this:
Or, if you want [Serde](https://github.com/serde-rs/serde) include the feature
like this:

```toml
[dependencies]
chrono = { version = "0.4", features = ["serde", "rustc-serialize"] }
chrono = { version = "0.4", features = ["serde"] }
```

> Note that Chrono's support for rustc-serialize is now considered deprecated.
Starting from 0.4.0 there is no further guarantee that
the features available in Serde will be also available to rustc-serialize,
and the support can be removed in any future major version.
**Rustc-serialize users are strongly recommended to migrate to Serde.**

Then put this in your crate root:

```rust
Expand Down
8 changes: 8 additions & 0 deletions src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,9 @@ pub mod rustc_serialize {
}
}

#[allow(deprecated)]
impl Decodable for TsSeconds<FixedOffset> {
#[allow(deprecated)]
fn decode<D: Decoder>(d: &mut D) -> Result<TsSeconds<FixedOffset>, D::Error> {
from(FixedOffset::east(0).timestamp_opt(d.read_i64()?, 0), d)
.map(TsSeconds)
Expand All @@ -717,13 +719,16 @@ pub mod rustc_serialize {
#[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>;

Expand All @@ -732,6 +737,7 @@ pub mod rustc_serialize {
}
}

#[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)
Expand All @@ -748,7 +754,9 @@ pub mod rustc_serialize {
}
}

#[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)))
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ pub use oldtime::Duration;
#[doc(no_inline)] pub use naive::{NaiveDate, IsoWeek, NaiveTime, NaiveDateTime};
pub use date::{Date, MIN_DATE, MAX_DATE};
pub use datetime::{DateTime, SecondsFormat};
#[cfg(feature = "rustc-serialize")] pub use datetime::rustc_serialize::TsSeconds;
#[cfg(feature = "rustc-serialize")]
pub use datetime::rustc_serialize::TsSeconds;
pub use format::{ParseError, ParseResult};
pub use round::SubsecRound;

Expand Down Expand Up @@ -451,6 +452,7 @@ pub mod naive {
pub use self::time::NaiveTime;
pub use self::datetime::NaiveDateTime;
#[cfg(feature = "rustc-serialize")]
#[allow(deprecated)]
pub use self::datetime::rustc_serialize::TsSeconds;


Expand Down
8 changes: 8 additions & 0 deletions src/naive/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,24 +1503,32 @@ pub mod rustc_serialize {

/// 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)
Expand Down