Skip to content

Commit

Permalink
feat: add support for jiff
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Jul 28, 2024
1 parent e32baa5 commit a20ca7a
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
chrono = { version = "0.4.38", default-features = false }
jiff = { version = "0.1.1", default-features = false }
6 changes: 5 additions & 1 deletion bounded-static/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ 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" ]

# 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 }
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
88 changes: 88 additions & 0 deletions bounded-static/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -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: '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);
}
}

0 comments on commit a20ca7a

Please sign in to comment.