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

Implement Data for chrono types #1743

Merged
merged 2 commits into from
Apr 29, 2021
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ You can find its changes [documented below](#070---2021-01-01).
- `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])
- GTK: added support for `content_insets` ([#1722] by [@jneem])
- `chrono` feature with `Data` support for [chrono](https://docs.rs/chrono/) types ([#1743] by [@r-ml])
r-ml marked this conversation as resolved.
Show resolved Hide resolved

### Changed

Expand Down Expand Up @@ -461,6 +462,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 @@ -690,6 +692,7 @@ Last release without a changelog :(
[#1722]: https://github.com/linebender/druid/pull/1722
[#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