Skip to content

Commit

Permalink
Implement Data for chrono types
Browse files Browse the repository at this point in the history
Closes #1736
  • Loading branch information
r-ml committed Apr 28, 2021
1 parent a73120c commit 0f41105
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ You can find its changes [documented below](#070---2021-01-01).
context-methods to implement disabled ([#1632] by [@xarvic])
- `LifeCycle::BuildFocusChain` to update the focus-chain ([#1632] by [@xarvic])
- `DisabledIf` widget wrapper to disable based on the state of Data and Env ([#1702] by [@xarvic])
- `chrono` feature with `Data` support for [chrono](https://docs.rs/chrono/) types ([#1743] by [@r-ml])
### Changed

- Warn on unhandled Commands ([#1533] by [@Maan2003])
Expand Down Expand Up @@ -459,6 +460,7 @@ Last release without a changelog :(
[@arthmis]: https://github.com/arthmis
[@ccqpein]: https://github.com/ccqpein
[@RichardPoole42]: https://github.com/RichardPoole42
[@r-ml]: https://github.com/r-ml

[#599]: https://github.com/linebender/druid/pull/599
[#611]: https://github.com/linebender/druid/pull/611
Expand Down Expand Up @@ -687,6 +689,7 @@ Last release without a changelog :(
[#1715]: https://github.com/linebender/druid/pull/1715
[#1724]: https://github.com/linebender/druid/pull/1724
[#1730]: https://github.com/linebender/druid/pull/1730
[#1743]: https://github.com/linebender/druid/pull/1743

[Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master
[0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0
Expand Down
1 change: 1 addition & 0 deletions druid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fnv = "1.0.7"
instant = { version = "0.1.6", features = ["wasm-bindgen"] }

# Optional dependencies
chrono = { version = "0.4.19", optional = true }
im = { version = "15.0.0", optional = true }
usvg = { version = "0.12.0", optional = true }

Expand Down
25 changes: 25 additions & 0 deletions druid/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ impl_data_simple!(std::net::IpAddr);
impl_data_simple!(std::net::SocketAddr);
impl_data_simple!(std::ops::RangeFull);
impl_data_simple!(druid::piet::InterpolationMode);
#[cfg(feature = "chrono")]
impl_data_simple!(chrono::Duration);
#[cfg(feature = "chrono")]
impl_data_simple!(chrono::naive::IsoWeek);
#[cfg(feature = "chrono")]
impl_data_simple!(chrono::naive::NaiveDate);
#[cfg(feature = "chrono")]
impl_data_simple!(chrono::naive::NaiveDateTime);
#[cfg(feature = "chrono")]
impl_data_simple!(chrono::naive::NaiveTime);

//TODO: remove me!?
impl_data_simple!(String);

Expand Down Expand Up @@ -545,6 +556,20 @@ impl Data for ImageBuf {
}
}

#[cfg(feature = "chrono")]
impl<Tz: chrono::offset::TimeZone + 'static> Data for chrono::Date<Tz> {
fn same(&self, other: &Self) -> bool {
self == other
}
}

#[cfg(feature = "chrono")]
impl<Tz: chrono::offset::TimeZone + 'static> Data for chrono::DateTime<Tz> {
fn same(&self, other: &Self) -> bool {
self == other
}
}

#[cfg(feature = "im")]
impl<T: Data> Data for im::Vector<T> {
fn same(&self, other: &Self) -> bool {
Expand Down

0 comments on commit 0f41105

Please sign in to comment.