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 | |
parent | ad487ffce9c5f2016b9c1caf7f3305d5e4cbe5f7 (diff) |
clock: Hide serde support behind feature flag `with-serde`
Signed-off-by: Uwe Klotz <uwe.klotz@slowtec.de>
-rw-r--r-- | Cargo.lock | 55 | ||||
-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 | ||||
-rw-r--r-- | crates/core/thin_edge_json/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/core/thin_edge_json/src/alarm.rs | 3 | ||||
-rw-r--r-- | crates/core/thin_edge_json/src/event.rs | 3 |
8 files changed, 56 insertions, 39 deletions
@@ -234,7 +234,7 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" name = "batcher" version = "0.5.2" dependencies = [ - "time 0.3.5", + "time 0.3.7", "tokio", ] @@ -352,7 +352,7 @@ dependencies = [ "test-case", "thin_edge_json", "thiserror", - "time 0.3.5", + "time 0.3.7", "tokio", "toml", "tracing", @@ -377,7 +377,7 @@ dependencies = [ "test-case", "thin_edge_json", "thiserror", - "time 0.3.5", + "time 0.3.7", "tokio", "toml", ] @@ -398,7 +398,7 @@ dependencies = [ "test-case", "thin_edge_json", "thiserror", - "time 0.3.5", + "time 0.3.7", ] [[package]] @@ -433,7 +433,7 @@ dependencies = [ "rcgen", "sha-1", "thiserror", - "time 0.3.5", + "time 0.3.7", "x509-parser", "zeroize", ] @@ -484,8 +484,7 @@ name = "clock" version = "0.5.2" dependencies = [ "mockall", - "serde", - "time 0.3.5", + "time 0.3.7", ] [[package]] @@ -625,7 +624,7 @@ checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" dependencies = [ "bstr", "csv-core", - "itoa", + "itoa 0.4.8", "ryu", "serde", ] @@ -1100,7 +1099,7 @@ checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" dependencies = [ "bytes", "fnv", - "itoa", + "itoa 0.4.8", ] [[package]] @@ -1156,7 +1155,7 @@ dependencies = [ "http-body", "httparse", "httpdate", - "itoa", + "itoa 0.4.8", "pin-project-lite", "socket2", "tokio", @@ -1230,6 +1229,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" [[package]] +name = "itoa" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" + +[[package]] name = "jackiechan" version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1652,6 +1657,15 @@ dependencies = [ ] [[package]] +name = "num_threads" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97ba99ba6393e2c3734791401b66902d981cb03bf190af674ca69949b6d5fb15" +dependencies = [ + "libc", +] + +[[package]] name = "object" version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2078,7 +2092,7 @@ checksum = "e2296a75ce93ea619bd9686d9f4b060f28845236e67d8666bcd02954e872b400" dependencies = [ "pem", "ring", - "time 0.3.5", + "time 0.3.7", "yasna", "zeroize", ] @@ -2457,7 +2471,7 @@ version = "1.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0ffa0837f2dfa6fb90868c2b5468cad482e175f7dad97e7421951e663f2b527" dependencies = [ - "itoa", + "itoa 0.4.8", "ryu", "serde", ] @@ -2469,7 +2483,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" dependencies = [ "form_urlencoded", - "itoa", + "itoa 0.4.8", "ryu", "serde", ] @@ -2670,7 +2684,7 @@ dependencies = [ "tedge_utils", "tempfile", "thiserror", - "time 0.3.5", + "time 0.3.7", "tokio", "tokio-test", "toml", @@ -2784,7 +2798,7 @@ dependencies = [ "test-case", "thin_edge_json", "thiserror", - "time 0.3.5", + "time 0.3.7", "tokio", "tokio-test", "toml", @@ -2880,7 +2894,7 @@ dependencies = [ "stats_alloc", "test-case", "thiserror", - "time 0.3.5", + "time 0.3.7", "walkdir", ] @@ -2925,12 +2939,13 @@ dependencies = [ [[package]] name = "time" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41effe7cfa8af36f439fac33861b66b049edc6f9a32331e2312660529c1c24ad" +checksum = "004cbc98f30fa233c61a38bc77e96a9106e65c88f2d3bef182ae952027e5753d" dependencies = [ - "itoa", + "itoa 1.0.1", "libc", + "num_threads", "serde", "time-macros", ] @@ -3556,7 +3571,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "346d34a236c9d3e5f3b9b74563f238f955bbd05fa0b8b4efa53c130c43982f4c" dependencies = [ - "time 0.3.5", + "time 0.3.7", ] [[package]] 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; diff --git a/crates/core/thin_edge_json/Cargo.toml b/crates/core/thin_edge_json/Cargo.toml index 9ed0471a..194c3473 100644 --- a/crates/core/thin_edge_json/Cargo.toml +++ b/crates/core/thin_edge_json/Cargo.toml @@ -8,7 +8,7 @@ rust-version = "1.58.1" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -clock = { path = "../../common/clock" } +clock = { path = "../../common/clock", features = ["with-serde"] } json-writer = { path = "../../common/json_writer" } serde = { version = "1.0", features = ["derive"] } serde_json = "1" diff --git a/crates/core/thin_edge_json/src/alarm.rs b/crates/core/thin_edge_json/src/alarm.rs index 1ace73d7..44e1dd7b 100644 --- a/crates/core/thin_edge_json/src/alarm.rs +++ b/crates/core/thin_edge_json/src/alarm.rs @@ -23,8 +23,9 @@ pub enum AlarmSeverity { #[derive(Debug, Deserialize, PartialEq)] pub struct ThinEdgeAlarmData { pub message: Option<String>, + #[serde(default)] - #[serde(deserialize_with = "clock::deserialize_iso8601_timestamp")] + #[serde(with = "clock::serde::rfc3339::option")] pub time: Option<OffsetDateTime>, } diff --git a/crates/core/thin_edge_json/src/event.rs b/crates/core/thin_edge_json/src/event.rs index fa58fdbc..ad313ab0 100644 --- a/crates/core/thin_edge_json/src/event.rs +++ b/crates/core/thin_edge_json/src/event.rs @@ -14,8 +14,9 @@ pub struct ThinEdgeEvent { #[derive(Debug, Deserialize, PartialEq)] pub struct ThinEdgeEventData { pub message: Option<String>, + #[serde(default)] - #[serde(deserialize_with = "clock::deserialize_iso8601_timestamp")] + #[serde(with = "clock::serde::rfc3339::option")] pub time: Option<OffsetDateTime>, } |