Skip to content

Commit

Permalink
fix time example
Browse files Browse the repository at this point in the history
  • Loading branch information
yanganto committed Oct 2, 2024
1 parent 1322f06 commit da50596
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions struct-patch/examples/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>.
// https://github.com/jean-airoldie/humantime-serde/issues/13#issuecomment-2388437558
time: Duration,
}

Expand All @@ -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));
}

0 comments on commit da50596

Please sign in to comment.