Skip to content

Commit

Permalink
add abi_stable feature
Browse files Browse the repository at this point in the history
  • Loading branch information
管唯宇 committed Feb 21, 2024
1 parent 60f8b74 commit 81f0c1a
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ std = ["alloc"]
clock = ["winapi", "iana-time-zone", "android-tzdata", "now"]
now = ["std"]
oldtime = []
abi_stable = ["dep:abi_stable"]
wasmbind = ["wasm-bindgen", "js-sys"]
unstable-locales = ["pure-rust-locales"]
# Note that rkyv-16, rkyv-32, and rkyv-64 are mutually exclusive.
Expand All @@ -44,6 +45,7 @@ serde = { version = "1.0.99", default-features = false, optional = true }
pure-rust-locales = { version = "0.8", optional = true }
rkyv = { version = "0.7.43", optional = true, default-features = false }
arbitrary = { version = "1.0.0", features = ["derive"], optional = true }
abi_stable = { version = "0.11.3", optional = true }

[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dependencies]
wasm-bindgen = { version = "0.2", optional = true }
Expand Down
17 changes: 17 additions & 0 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ mod tests;
archive(compare(PartialEq, PartialOrd))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[cfg_attr(feature = "abi_stable", derive(abi_stable::StableAbi))]
#[cfg_attr(feature = "abi_stable", repr(C))]
#[cfg_attr(feature = "abi_stable", sabi(bound(Tz::Offset: abi_stable::StableAbi)))]
pub struct DateTime<Tz: TimeZone> {
datetime: NaiveDateTime,
offset: Tz::Offset,
Expand Down Expand Up @@ -1839,3 +1842,17 @@ fn test_decodable_json_timestamps<FUtc, FFixed, FLocal, E>(
Utc.with_ymd_and_hms(1969, 12, 31, 23, 59, 59).unwrap()
);
}

#[cfg(all(feature = "abi_stable", test))]
mod test_abi_stable {
use super::*;
struct _DateTimeUtcIsAbiStable
where
DateTime<Utc>: abi_stable::StableAbi;
struct _DateTimeFixedOffsetIsAbiStable
where
DateTime<FixedOffset>: abi_stable::StableAbi;
struct _DateTimeLocalIsAbiStable
where
DateTime<Local>: abi_stable::StableAbi;
}
2 changes: 2 additions & 0 deletions src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ impl num_traits::FromPrimitive for Month {
/// A duration in calendar months
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "abi_stable", derive(abi_stable::StableAbi))]
#[cfg_attr(feature = "abi_stable", repr(transparent))]
pub struct Months(pub(crate) u32);

impl Months {
Expand Down
2 changes: 2 additions & 0 deletions src/naive/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ mod tests;
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[cfg_attr(feature = "abi_stable", derive(abi_stable::StableAbi))]
#[cfg_attr(feature = "abi_stable", repr(transparent))]
pub struct NaiveDate {
yof: NonZeroI32, // (year << 13) | of
}
Expand Down
2 changes: 2 additions & 0 deletions src/naive/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ pub const MAX_DATETIME: NaiveDateTime = NaiveDateTime::MAX;
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "abi_stable", derive(abi_stable::StableAbi))]
#[cfg_attr(feature = "abi_stable", repr(C))]
pub struct NaiveDateTime {
date: NaiveDate,
time: NaiveTime,
Expand Down
2 changes: 2 additions & 0 deletions src/naive/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ mod tests;
archive_attr(derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[cfg_attr(feature = "abi_stable", derive(abi_stable::StableAbi))]
#[cfg_attr(feature = "abi_stable", repr(C))]
pub struct NaiveTime {
secs: u32,
frac: u32,
Expand Down
2 changes: 2 additions & 0 deletions src/offset/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use crate::naive::{NaiveDate, NaiveDateTime};
archive_attr(derive(Clone, Copy, PartialEq, Eq, Hash, Debug))
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[cfg_attr(feature = "abi_stable", derive(abi_stable::StableAbi))]
#[cfg_attr(feature = "abi_stable", repr(transparent))]
pub struct FixedOffset {
local_minus_utc: i32,
}
Expand Down
2 changes: 2 additions & 0 deletions src/offset/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ mod tz_info;
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "abi_stable", derive(abi_stable::StableAbi))]
#[cfg_attr(feature = "abi_stable", repr(transparent))]
pub struct Local;

impl Local {
Expand Down
2 changes: 2 additions & 0 deletions src/offset/utc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ use crate::{Date, DateTime};
)]
#[cfg_attr(feature = "rkyv-validation", archive(check_bytes))]
#[cfg_attr(all(feature = "arbitrary", feature = "std"), derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "abi_stable", derive(abi_stable::StableAbi))]
#[cfg_attr(feature = "abi_stable", repr(transparent))]
pub struct Utc;

#[cfg(feature = "now")]
Expand Down

0 comments on commit 81f0c1a

Please sign in to comment.