Skip to content
Draft
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
16 changes: 11 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta, 1.64.0]
rust: [stable, beta, 1.70.0]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand Down 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 All @@ -93,7 +99,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta, 1.64.0]
rust: [stable, beta, 1.70.0]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -111,7 +117,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [ stable, beta, 1.64.0 ]
rust: [ stable, beta, 1.70.0 ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -129,7 +135,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [ stable, beta, 1.64.0 ]
rust: [ stable, beta, 1.70.0 ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -148,7 +154,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [ stable, beta, 1.64.0 ]
rust: [ stable, beta, 1.70.0 ]
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = ["bounded-static", "bounded-static-derive"]

[workspace.package]
version = "0.8.0"
rust-version = "1.64.0"
rust-version = "1.70.0"
edition = "2021"
authors = ["FujiApple <fujiapple852@gmail.com>"]
repository = "https://github.com/fujiapple852/bounded-static"
Expand All @@ -23,4 +23,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.14", 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 }

[dev-dependencies]
test-case.workspace = true
Expand Down
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.14/jiff/struct.Zoned.html)
//! - [`Timestamp`](https://docs.rs/jiff/0.1.14/jiff/struct.Timestamp.html)
//! - [`DateTime`](https://docs.rs/jiff/0.1.14/jiff/civil/struct.DateTime.html)
//! - [`Date`](https://docs.rs/jiff/0.1.14/jiff/civil/struct.Date.html)
//! - [`Time`](https://docs.rs/jiff/0.1.14/jiff/civil/struct.Time.html)
//!
//! # Examples
//!
Expand Down Expand Up @@ -1024,6 +1030,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 @@ -1843,3 +1881,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);
}
}
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[licenses]
version = 2
allow = [ "Apache-2.0", "MPL-2.0", "Unicode-DFS-2016" ]
allow = [ "Apache-2.0", "MPL-2.0", "Unicode-DFS-2016", "MIT" ]
confidence-threshold = 0.8
exceptions = []

Expand Down