Skip to content
Snippets Groups Projects
Commit 8f5d089f authored by Ian Jackson's avatar Ian Jackson
Browse files

Revert "humantime_serde_option: New module in tor-basic-utils"

We have upstreamed this code.

This reverts commit 6193c9d9.
parent 409c5dd6
No related branches found
No related tags found
1 merge request!406Replace humantime_serde_option with upstream code
......@@ -3098,8 +3098,6 @@ name = "tor-basic-utils"
version = "0.1.0"
dependencies = [
"educe",
"humantime-serde",
"serde",
]
[[package]]
......
......@@ -11,12 +11,6 @@ categories = ["rust-patterns"] # We must put *something* here and this will do
repository = "https://gitlab.torproject.org/tpo/core/arti.git/"
[dependencies]
serde = { version = "1.0.103", features = ["derive"], optional = true }
humantime-serde-crate = { package = "humantime-serde", version = "1", optional = true }
[features]
default = ["humantime-serde"]
humantime-serde = ["humantime-serde-crate", "serde"]
[dev-dependencies]
educe = "0.4.6"
//! Module to adaopt `humantime_serde` to `Option<Duration>`
use humantime_serde_crate::Serde as HtSerde;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
/// Serializes an `Option<Duration>` or `Option<SystemTime>` via the humantime crate.
pub fn serialize<T, S>(d: &Option<T>, s: S) -> Result<S::Ok, S::Error>
where
for<'a> HtSerde<&'a T>: Serialize,
S: Serializer,
{
let nested: Option<HtSerde<&T>> = d.as_ref().map(Into::into);
nested.serialize(s)
}
/// Deserialize an `Option<Duration>` or `Option<SystemTime>` via the humantime crate.
pub fn deserialize<'a, T, D>(d: D) -> Result<Option<T>, D::Error>
where
HtSerde<T>: Deserialize<'a>,
D: Deserializer<'a>,
{
let got: Option<HtSerde<T>> = Deserialize::deserialize(d)?;
Ok(got.map(HtSerde::into_inner))
}
......@@ -41,9 +41,6 @@
use std::fmt;
#[cfg(feature = "humantime-serde")]
pub mod humantime_serde_option;
// ----------------------------------------------------------------------
/// Function with the signature of `Debug::fmt` that just prints `".."`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment