diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2ca6e6..9e08d14 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,6 +83,12 @@ jobs: command: check args: --workspace --no-default-features --features chrono-clock + - name: check --no-default-features --features jiff + uses: actions-rs/cargo@v1 + with: + command: check + args: --workspace --no-default-features --features jiff + - name: check --all-features uses: actions-rs/cargo@v1 with: diff --git a/Cargo.toml b/Cargo.toml index 26e7e15..0448d96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,4 +22,5 @@ smol_str = { version = "0.2.2", default-features = false } smallvec = { version = "1.13.2", default-features = false } smartstring = { version = "1.0.1", default-features = false } ahash = { version = "0.8.11", default-features = false } -chrono = { version = "0.4.38", default-features = false } \ No newline at end of file +chrono = { version = "0.4.38", default-features = false } +jiff = { version = "0.1.1", default-features = false } \ No newline at end of file diff --git a/bounded-static/Cargo.toml b/bounded-static/Cargo.toml index bf28097..4588251 100644 --- a/bounded-static/Cargo.toml +++ b/bounded-static/Cargo.toml @@ -21,7 +21,7 @@ alloc = [] collections = [ "alloc" ] # Enable impls of [To|Into]BoundedStatic for other types in std. -std = [ "alloc", "ahash?/std", "chrono?/std" ] +std = [ "alloc", "ahash?/std", "chrono?/std", "jiff?/std" ] # Enable the ToStatic custom derive macro. derive = [ "bounded-static-derive" ] @@ -29,6 +29,9 @@ derive = [ "bounded-static-derive" ] # Enable the clock feature for chrono. chrono-clock = [ "chrono", "chrono/clock" ] +# Enable impls of [To|Into]BoundedStatic for types in the jiff crate. +jiff = [ "dep:jiff", "jiff/alloc" ] + [dependencies] bounded-static-derive = { workspace = true, optional = true } smol_str = { workspace = true, optional = true, default-features = false } @@ -36,6 +39,7 @@ smallvec = { workspace = true, optional = true, default-features = false } smartstring = { workspace = true, optional = true, default-features = false } ahash = { workspace = true, optional = true, default-features = false } chrono = { workspace = true, optional = true, default-features = false } +jiff = { workspace = true, optional = true, default-features = false } [package.metadata.docs.rs] all-features = true diff --git a/bounded-static/src/lib.rs b/bounded-static/src/lib.rs index bc763fe..7eb9669 100644 --- a/bounded-static/src/lib.rs +++ b/bounded-static/src/lib.rs @@ -77,6 +77,12 @@ //! - [`NaiveTime`](https://docs.rs/chrono/0.4.38/chrono/naive/struct.NaiveTime.html) //! - `chrono-clock` for: //! - [`Local`](https://docs.rs/chrono/0.4.38/chrono/struct.Local.html) +//! - `jiff` for: +//! - [`Zoned`](https://docs.rs/jiff/0.1.1/jiff/struct.Zoned.html) +//! - [`Timestamp`](https://docs.rs/jiff/0.1.1/jiff/struct.Timestamp.html) +//! - [`DateTime`](https://docs.rs/jiff/0.1.1/jiff/civil/struct.DateTime.html) +//! - [`Date`](https://docs.rs/jiff/0.1.1/jiff/civil/struct.Date.html) +//! - [`Time`](https://docs.rs/jiff/0.1.1/jiff/civil/struct.Time.html) //! //! # Examples //! @@ -1021,6 +1027,38 @@ make_copy_impl!(chrono::naive::NaiveTime); make_copy_impl!(chrono::Local); // No implementation for chrono::NaiveWeek as it's not Copy nor Clone. +#[cfg(feature = "jiff")] +/// [`ToBoundedStatic`] impl for `jiff::Zoned`. +impl ToBoundedStatic for jiff::Zoned { + type Static = Self; + + fn to_static(&self) -> Self::Static { + self.clone() + } +} + +#[cfg(feature = "jiff")] +/// No-op [`IntoBoundedStatic`] impl for `jiff::Zoned`. +impl IntoBoundedStatic for jiff::Zoned { + type Static = Self; + + fn into_static(self) -> Self::Static { + self + } +} + +#[cfg(feature = "jiff")] +make_copy_impl!(jiff::Timestamp); + +#[cfg(feature = "jiff")] +make_copy_impl!(jiff::civil::DateTime); + +#[cfg(feature = "jiff")] +make_copy_impl!(jiff::civil::Date); + +#[cfg(feature = "jiff")] +make_copy_impl!(jiff::civil::Time); + #[cfg(test)] mod core_tests { use super::*; @@ -1931,3 +1969,53 @@ mod chrono_clock_tests { ensure_static(to_static); } } + +#[cfg(feature = "jiff")] +#[cfg(test)] +mod jiff_tests { + use super::*; + + fn ensure_static(t: T) { + drop(t); + } + + #[cfg(feature = "std")] + #[test] + fn test_jiff_zoned() { + let value = jiff::Zoned::now(); + let to_static = value.to_static(); + ensure_static(to_static); + } + + #[cfg(feature = "std")] + #[test] + fn test_jiff_timestamp() { + let value = jiff::Timestamp::now(); + let to_static = value.to_static(); + ensure_static(to_static); + } + + #[cfg(feature = "std")] + #[test] + fn test_jiff_civil_datetime() { + let value = jiff::civil::DateTime::default(); + let to_static = value.to_static(); + ensure_static(to_static); + } + + #[cfg(feature = "std")] + #[test] + fn test_jiff_civil_date() { + let value = jiff::civil::Date::default(); + let to_static = value.to_static(); + ensure_static(to_static); + } + + #[cfg(feature = "std")] + #[test] + fn test_jiff_civil_time() { + let value = jiff::civil::Time::default(); + let to_static = value.to_static(); + ensure_static(to_static); + } +}