From dc576013e5c17227f3ed4a31026425385dbaa251 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 12 Mar 2024 18:11:06 +0100 Subject: [PATCH] Add optional serde support and make MonotonicTime serializable --- CHANGELOG.md | 5 ++++- asynchronix/Cargo.toml | 5 +++++ asynchronix/src/time/monotonic_time.rs | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 451dca9..1833adb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# unreleased + +- Add `serde` feature and serialization support for `MonotonicTime`. + # 0.2.1 (2024-03-06) ### Added @@ -12,7 +16,6 @@ - Update copyright in MIT license to include contributors. - # 0.2.0 (2023-08-15) ### Added (API-breaking changes) diff --git a/asynchronix/Cargo.toml b/asynchronix/Cargo.toml index f5950ac..a639579 100644 --- a/asynchronix/Cargo.toml +++ b/asynchronix/Cargo.toml @@ -25,6 +25,7 @@ autotests = false dev-hooks = [] # Logging of performance-related statistics; development only. dev-logs = [] +serde = ["dep:serde"] [dependencies] async-event = "0.1" @@ -39,6 +40,10 @@ slab = "0.4" spin_sleep = "1" st3 = "0.4" +[dependencies.serde] +version = "1" +optional = true + [target.'cfg(asynchronix_loom)'.dependencies] loom = "0.5" waker-fn = "1.1" diff --git a/asynchronix/src/time/monotonic_time.rs b/asynchronix/src/time/monotonic_time.rs index 85a5579..e27ff56 100644 --- a/asynchronix/src/time/monotonic_time.rs +++ b/asynchronix/src/time/monotonic_time.rs @@ -52,6 +52,7 @@ const NANOS_PER_SEC: u32 = 1_000_000_000; /// assert_eq!(timestamp.subsec_nanos(), 443_654_321); /// ``` #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct MonotonicTime { /// The number of whole seconds in the future (if positive) or in the past /// (if negative) of 1970-01-01 00:00:00 TAI.