Skip to content

Commit a20ca7a

Browse files
committed
feat: add support for jiff
1 parent e32baa5 commit a20ca7a

4 files changed

Lines changed: 101 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ jobs:
8383
command: check
8484
args: --workspace --no-default-features --features chrono-clock
8585

86+
- name: check --no-default-features --features jiff
87+
uses: actions-rs/cargo@v1
88+
with:
89+
command: check
90+
args: --workspace --no-default-features --features jiff
91+
8692
- name: check --all-features
8793
uses: actions-rs/cargo@v1
8894
with:

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ smol_str = { version = "0.2.2", default-features = false }
2222
smallvec = { version = "1.13.2", default-features = false }
2323
smartstring = { version = "1.0.1", default-features = false }
2424
ahash = { version = "0.8.11", default-features = false }
25-
chrono = { version = "0.4.38", default-features = false }
25+
chrono = { version = "0.4.38", default-features = false }
26+
jiff = { version = "0.1.1", default-features = false }

bounded-static/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,25 @@ alloc = []
2121
collections = [ "alloc" ]
2222

2323
# Enable impls of [To|Into]BoundedStatic for other types in std.
24-
std = [ "alloc", "ahash?/std", "chrono?/std" ]
24+
std = [ "alloc", "ahash?/std", "chrono?/std", "jiff?/std" ]
2525

2626
# Enable the ToStatic custom derive macro.
2727
derive = [ "bounded-static-derive" ]
2828

2929
# Enable the clock feature for chrono.
3030
chrono-clock = [ "chrono", "chrono/clock" ]
3131

32+
# Enable impls of [To|Into]BoundedStatic for types in the jiff crate.
33+
jiff = [ "dep:jiff", "jiff/alloc" ]
34+
3235
[dependencies]
3336
bounded-static-derive = { workspace = true, optional = true }
3437
smol_str = { workspace = true, optional = true, default-features = false }
3538
smallvec = { workspace = true, optional = true, default-features = false }
3639
smartstring = { workspace = true, optional = true, default-features = false }
3740
ahash = { workspace = true, optional = true, default-features = false }
3841
chrono = { workspace = true, optional = true, default-features = false }
42+
jiff = { workspace = true, optional = true, default-features = false }
3943

4044
[package.metadata.docs.rs]
4145
all-features = true

bounded-static/src/lib.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@
7777
//! - [`NaiveTime`](https://docs.rs/chrono/0.4.38/chrono/naive/struct.NaiveTime.html)
7878
//! - `chrono-clock` for:
7979
//! - [`Local`](https://docs.rs/chrono/0.4.38/chrono/struct.Local.html)
80+
//! - `jiff` for:
81+
//! - [`Zoned`](https://docs.rs/jiff/0.1.1/jiff/struct.Zoned.html)
82+
//! - [`Timestamp`](https://docs.rs/jiff/0.1.1/jiff/struct.Timestamp.html)
83+
//! - [`DateTime`](https://docs.rs/jiff/0.1.1/jiff/civil/struct.DateTime.html)
84+
//! - [`Date`](https://docs.rs/jiff/0.1.1/jiff/civil/struct.Date.html)
85+
//! - [`Time`](https://docs.rs/jiff/0.1.1/jiff/civil/struct.Time.html)
8086
//!
8187
//! # Examples
8288
//!
@@ -1021,6 +1027,38 @@ make_copy_impl!(chrono::naive::NaiveTime);
10211027
make_copy_impl!(chrono::Local);
10221028
// No implementation for chrono::NaiveWeek as it's not Copy nor Clone.
10231029

1030+
#[cfg(feature = "jiff")]
1031+
/// [`ToBoundedStatic`] impl for `jiff::Zoned`.
1032+
impl ToBoundedStatic for jiff::Zoned {
1033+
type Static = Self;
1034+
1035+
fn to_static(&self) -> Self::Static {
1036+
self.clone()
1037+
}
1038+
}
1039+
1040+
#[cfg(feature = "jiff")]
1041+
/// No-op [`IntoBoundedStatic`] impl for `jiff::Zoned`.
1042+
impl IntoBoundedStatic for jiff::Zoned {
1043+
type Static = Self;
1044+
1045+
fn into_static(self) -> Self::Static {
1046+
self
1047+
}
1048+
}
1049+
1050+
#[cfg(feature = "jiff")]
1051+
make_copy_impl!(jiff::Timestamp);
1052+
1053+
#[cfg(feature = "jiff")]
1054+
make_copy_impl!(jiff::civil::DateTime);
1055+
1056+
#[cfg(feature = "jiff")]
1057+
make_copy_impl!(jiff::civil::Date);
1058+
1059+
#[cfg(feature = "jiff")]
1060+
make_copy_impl!(jiff::civil::Time);
1061+
10241062
#[cfg(test)]
10251063
mod core_tests {
10261064
use super::*;
@@ -1931,3 +1969,53 @@ mod chrono_clock_tests {
19311969
ensure_static(to_static);
19321970
}
19331971
}
1972+
1973+
#[cfg(feature = "jiff")]
1974+
#[cfg(test)]
1975+
mod jiff_tests {
1976+
use super::*;
1977+
1978+
fn ensure_static<T: 'static>(t: T) {
1979+
drop(t);
1980+
}
1981+
1982+
#[cfg(feature = "std")]
1983+
#[test]
1984+
fn test_jiff_zoned() {
1985+
let value = jiff::Zoned::now();
1986+
let to_static = value.to_static();
1987+
ensure_static(to_static);
1988+
}
1989+
1990+
#[cfg(feature = "std")]
1991+
#[test]
1992+
fn test_jiff_timestamp() {
1993+
let value = jiff::Timestamp::now();
1994+
let to_static = value.to_static();
1995+
ensure_static(to_static);
1996+
}
1997+
1998+
#[cfg(feature = "std")]
1999+
#[test]
2000+
fn test_jiff_civil_datetime() {
2001+
let value = jiff::civil::DateTime::default();
2002+
let to_static = value.to_static();
2003+
ensure_static(to_static);
2004+
}
2005+
2006+
#[cfg(feature = "std")]
2007+
#[test]
2008+
fn test_jiff_civil_date() {
2009+
let value = jiff::civil::Date::default();
2010+
let to_static = value.to_static();
2011+
ensure_static(to_static);
2012+
}
2013+
2014+
#[cfg(feature = "std")]
2015+
#[test]
2016+
fn test_jiff_civil_time() {
2017+
let value = jiff::civil::Time::default();
2018+
let to_static = value.to_static();
2019+
ensure_static(to_static);
2020+
}
2021+
}

0 commit comments

Comments
 (0)