From da5059663174b98083f493a8ae47db46b1caa88c Mon Sep 17 00:00:00 2001 From: Antonio Yang Date: Wed, 2 Oct 2024 20:37:29 +0800 Subject: [PATCH] fix time example --- struct-patch/examples/time.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/struct-patch/examples/time.rs b/struct-patch/examples/time.rs index b284eb3..3d0b097 100644 --- a/struct-patch/examples/time.rs +++ b/struct-patch/examples/time.rs @@ -6,7 +6,10 @@ use struct_patch::Patch; #[patch(name = "FileConfig", attribute(derive(Deserialize, Debug)))] struct Config { #[serde(with = "humantime_serde")] - #[patch(attribute(serde(with = "humantime_serde")))] + #[patch(attribute(serde(with = "humantime_serde", default)))] + // NOTE: + // We need extra default parameter for Option. + // https://github.com/jean-airoldie/humantime-serde/issues/13#issuecomment-2388437558 time: Duration, } @@ -21,14 +24,9 @@ fn main() { patched.apply(patch); assert_eq!(patched.time, Duration::from_millis(200)); - // NOTE - // Following code does not work, because `humantime_serde` does not allow `Option<>` field - // anymore. - // https://github.com/jean-airoldie/humantime-serde/issues/13 - // - // let empty_patch: FileConfig = toml::from_str("").unwrap(); + let empty_patch: FileConfig = toml::from_str("").unwrap(); - // let mut patched = config.clone(); - // patched.apply(empty_patch); - // assert_eq!(patched.time, Duration::from_millis(500)); + let mut patched = config.clone(); + patched.apply(empty_patch); + assert_eq!(patched.time, Duration::from_millis(500)); }