diff options
author | Uwe Klotz <uwe.klotz@slowtec.de> | 2022-02-15 17:54:06 +0100 |
---|---|---|
committer | Uwe Klotz <uwe.klotz@slowtec.de> | 2022-02-15 17:54:06 +0100 |
commit | e53d4d76b629ee6198f807e12f93e189ff3b5be8 (patch) | |
tree | ea383ed9ef3604f1c137d3e008d50c6052cf4998 /crates/common/clock | |
parent | ad487ffce9c5f2016b9c1caf7f3305d5e4cbe5f7 (diff) |
clock: Hide serde support behind feature flag `with-serde`
Signed-off-by: Uwe Klotz <uwe.klotz@slowtec.de>
Diffstat (limited to 'crates/common/clock')
-rw-r--r-- | crates/common/clock/Cargo.toml | 7 | ||||
-rw-r--r-- | crates/common/clock/src/lib.rs | 18 | ||||
-rw-r--r-- | crates/common/clock/src/serde/mod.rs | 1 | ||||
-rw-r--r-- | crates/common/clock/src/serde/rfc3339.rs | 6 |
4 files changed, 16 insertions, 16 deletions
diff --git a/crates/common/clock/Cargo.toml b/crates/common/clock/Cargo.toml index 8615da7e..94dc87da 100644 --- a/crates/common/clock/Cargo.toml +++ b/crates/common/clock/Cargo.toml @@ -7,5 +7,8 @@ rust-version = "1.58.1" [dependencies] mockall = "0.10" -serde = { version = "1.0", features = ["derive"] } -time = { version = "0.3", features = ["serde-human-readable"] } +time = "0.3.7" + +[features] +default = [] +with-serde = ["time/serde-well-known"] diff --git a/crates/common/clock/src/lib.rs b/crates/common/clock/src/lib.rs index 7c87d4a0..a97ee9df 100644 --- a/crates/common/clock/src/lib.rs +++ b/crates/common/clock/src/lib.rs @@ -1,6 +1,8 @@ use mockall::automock; -use serde::{Deserialize, Deserializer}; -use time::{format_description::well_known::Rfc3339, OffsetDateTime}; +use time::OffsetDateTime; + +#[cfg(feature = "with-serde")] +pub mod serde; pub type Timestamp = OffsetDateTime; @@ -17,15 +19,3 @@ impl Clock for WallClock { OffsetDateTime::now_utc() } } - -pub fn deserialize_iso8601_timestamp<'de, D>( - deserializer: D, -) -> Result<Option<OffsetDateTime>, D::Error> -where - D: Deserializer<'de>, -{ - let timestamp = String::deserialize(deserializer)?; - OffsetDateTime::parse(timestamp.as_str(), &Rfc3339) - .map_err(serde::de::Error::custom) - .map(Some) -} diff --git a/crates/common/clock/src/serde/mod.rs b/crates/common/clock/src/serde/mod.rs new file mode 100644 index 00000000..a1646141 --- /dev/null +++ b/crates/common/clock/src/serde/mod.rs @@ -0,0 +1 @@ +pub mod rfc3339; diff --git a/crates/common/clock/src/serde/rfc3339.rs b/crates/common/clock/src/serde/rfc3339.rs new file mode 100644 index 00000000..abb36da6 --- /dev/null +++ b/crates/common/clock/src/serde/rfc3339.rs @@ -0,0 +1,6 @@ +/// Re-exported module +/// +/// Use this module in combination with serde's [`#[with]`][with] attribute. +/// +/// [with]: https://serde.rs/field-attrs.html#with +pub use time::serde::rfc3339::option; |