mirror of
https://github.com/BurntSushi/jiff.git
synced 2025-12-23 08:47:45 +00:00
jiff-icu: compatibility fixes
I guess we can't just drop the `std` feature quite yet, since Jiff only implements `std::error::Error` and not `core::error::Error`. Sigh.
This commit is contained in:
parent
11b286deed
commit
b0512f4ef4
4 changed files with 29 additions and 12 deletions
|
|
@ -27,9 +27,12 @@ bench = false
|
|||
path = "src/lib.rs"
|
||||
|
||||
[features]
|
||||
default = ["alloc", "time"]
|
||||
default = ["std", "zoned"]
|
||||
std = ["jiff/std", "alloc"]
|
||||
alloc = ["jiff/alloc", "icu_calendar/alloc", "icu_time?/alloc"]
|
||||
time = ["dep:icu_time"]
|
||||
# Compiled data is needed for parsing IANA time zone identifiers used by Jiff.
|
||||
zoned = ["time", "icu_time?/compiled_data"]
|
||||
|
||||
[dependencies]
|
||||
jiff = { version = "0.2.11", path = "../..", default-features = false }
|
||||
|
|
|
|||
|
|
@ -43,6 +43,11 @@ impl core::fmt::Display for Error {
|
|||
}
|
||||
}
|
||||
|
||||
// Why do we use `core::error::Error` here despite the fact that
|
||||
// we have a `std` feature? Well, because Jiff's `Error` type only
|
||||
// implements `std::error::Error` and can't (non-annoyingly) implement
|
||||
// `core::error::Error` because of its MSRV.
|
||||
#[cfg(feature = "std")]
|
||||
impl core::error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
|
||||
match self.kind {
|
||||
|
|
|
|||
|
|
@ -153,7 +153,7 @@ assert_eq!(zdt.to_string(), "2025-02-02T17:30:00-05:00[America/New_York]");
|
|||
#![no_std]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(any(test, feature = "std"))]
|
||||
extern crate std;
|
||||
|
||||
#[cfg(any(test, feature = "alloc"))]
|
||||
|
|
@ -163,20 +163,24 @@ use icu_calendar::{
|
|||
types::Weekday as IcuWeekday, AsCalendar as IcuAsCalendar,
|
||||
Date as IcuDate, Iso,
|
||||
};
|
||||
#[cfg(feature = "time")]
|
||||
#[cfg(feature = "zoned")]
|
||||
use icu_time::{
|
||||
provider::TimeZoneVariant,
|
||||
zone::{models::Full, UtcOffset as IcuUtcOffset},
|
||||
DateTime as IcuDateTime, Time as IcuTime, TimeZone as IcuTimeZone,
|
||||
provider::TimeZoneVariant, zone::models::Full, TimeZone as IcuTimeZone,
|
||||
TimeZoneInfo as IcuTimeZoneInfo, ZonedDateTime as IcuZonedDateTime,
|
||||
};
|
||||
#[cfg(feature = "time")]
|
||||
use icu_time::{
|
||||
zone::UtcOffset as IcuUtcOffset, DateTime as IcuDateTime, Time as IcuTime,
|
||||
};
|
||||
|
||||
use jiff::civil::{Date as JiffDate, Weekday as JiffWeekday};
|
||||
#[cfg(feature = "time")]
|
||||
use jiff::{
|
||||
civil::{DateTime as JiffDateTime, Time as JiffTime},
|
||||
tz::{Offset as JiffOffset, TimeZone as JiffTimeZone},
|
||||
Zoned as JiffZoned,
|
||||
tz::Offset as JiffOffset,
|
||||
};
|
||||
#[cfg(feature = "zoned")]
|
||||
use jiff::{tz::TimeZone as JiffTimeZone, Zoned as JiffZoned};
|
||||
|
||||
use self::error::err;
|
||||
pub use self::{
|
||||
|
|
@ -637,7 +641,7 @@ impl ConvertTryFrom<JiffOffset> for IcuUtcOffset {
|
|||
///
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
#[cfg(feature = "time")]
|
||||
#[cfg(feature = "zoned")]
|
||||
impl ConvertFrom<JiffTimeZone> for IcuTimeZone {
|
||||
fn convert_from(v: JiffTimeZone) -> IcuTimeZone {
|
||||
IcuTimeZone::convert_from(&v)
|
||||
|
|
@ -646,7 +650,7 @@ impl ConvertFrom<JiffTimeZone> for IcuTimeZone {
|
|||
|
||||
/// Converts from a [`&jiff::tz::TimeZone`](jiff::tz::TimeZone) to a
|
||||
/// [`icu_time::TimeZone`].
|
||||
#[cfg(feature = "time")]
|
||||
#[cfg(feature = "zoned")]
|
||||
impl<'a> ConvertFrom<&'a JiffTimeZone> for IcuTimeZone {
|
||||
fn convert_from(v: &'a JiffTimeZone) -> IcuTimeZone {
|
||||
let Some(iana_name) = v.iana_name() else {
|
||||
|
|
@ -683,7 +687,7 @@ impl<'a> ConvertFrom<&'a JiffTimeZone> for IcuTimeZone {
|
|||
///
|
||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||
/// ```
|
||||
#[cfg(feature = "time")]
|
||||
#[cfg(feature = "zoned")]
|
||||
impl<'a> ConvertFrom<&'a JiffZoned>
|
||||
for IcuZonedDateTime<Iso, IcuTimeZoneInfo<Full>>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ cd "$(dirname "$0")/.."
|
|||
integrations=(
|
||||
"jiff-diesel mysql"
|
||||
"jiff-diesel postgres"
|
||||
"jiff-icu alloc,time"
|
||||
"jiff-icu std,zoned"
|
||||
"jiff-sqlx postgres"
|
||||
"jiff-sqlx sqlite"
|
||||
)
|
||||
|
|
@ -32,6 +32,11 @@ done
|
|||
# doctests to pass for certain feature combinations.
|
||||
integrations=(
|
||||
"jiff-icu alloc"
|
||||
"jiff-icu std"
|
||||
"jiff-icu time"
|
||||
"jiff-icu zoned"
|
||||
"jiff-icu alloc,zoned"
|
||||
"jiff-icu std,zoned"
|
||||
)
|
||||
for v in "${integrations[@]}"; do
|
||||
crate="$(echo $v | awk '{print $1}')"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue