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 27, 2021
1 parent e0715c1 commit 7c377e0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 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
### Changed

- Warn on unhandled Commands ([#1533] by [@Maan2003])
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 7c377e0

Please sign in to comment.