From cf5eabb9647e6d53ec29a3f7de599a38dbfd5490 Mon Sep 17 00:00:00 2001 From: Luke Hoersten Date: Tue, 28 Jul 2026 18:09:57 -0500 Subject: Merge the two device state files and reduce mutation The registry (device names) and service-state (sync results) were two JSON files keyed the same way, split only for a TypeScript-compatibility that is moot now that the fabric identity cannot migrate between implementations. Merge them into one devices.json with a DeviceRecord per node, which also removes the parallel-map join in status and collapses the per-command load/store pairs. identity.json stays separate as a write-once secret. Also, from a reduction/immutability review: - Fix with_timeout passing a literal "{what}" instead of the error context - Drop needless mut: CompactDuration and parse_wall_clock become immutable expressions; run_status filters with a predicate instead of a mutator; sync_one extracts write_zone_and_dst; InspectOutcome gains Default plus a failed() constructor - Share a join_ids helper and a devices_path helper; add IdentityReport From; minor combinator tidy-ups 35 unit tests, clippy clean. --- src/time.rs | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'src/time.rs') diff --git a/src/time.rs b/src/time.rs index 6c38cc6..6616194 100644 --- a/src/time.rs +++ b/src/time.rs @@ -188,19 +188,16 @@ impl fmt::Display for CompactDuration { let hours = (total_seconds % 86_400) / 3_600; let minutes = (total_seconds % 3_600) / 60; let seconds = total_seconds % 60; - let mut parts: Vec = Vec::new(); - if days > 0 { - parts.push(format!("{days}d")); - } - if hours > 0 { - parts.push(format!("{hours}h")); - } - if minutes > 0 { - parts.push(format!("{minutes}m")); - } - if seconds > 0 && days == 0 { - parts.push(format!("{seconds}s")); - } + let parts: Vec = [ + (days > 0).then(|| format!("{days}d")), + (hours > 0).then(|| format!("{hours}h")), + (minutes > 0).then(|| format!("{minutes}m")), + // Seconds are dropped once days appear (see the doc comment). + (seconds > 0 && days == 0).then(|| format!("{seconds}s")), + ] + .into_iter() + .flatten() + .collect(); f.write_str(&parts.join(" ")) } } @@ -353,18 +350,16 @@ pub fn parse_wall_clock(input: &str) -> Result { .map_err(|_| format!("cannot parse {p:?} in {input:?} as a number")) }) .collect::>()?; - let (mut hour, minute, second) = (numbers[0], numbers[1], *numbers.get(2).unwrap_or(&0)); - - match meridiem { - Some(pm) => { - if !(1..=12).contains(&hour) { - return Err(format!("hour in {input:?} must be 1-12 with am/pm")); - } - hour = if pm { hour % 12 + 12 } else { hour % 12 }; + let (hour, minute, second) = (numbers[0], numbers[1], *numbers.get(2).unwrap_or(&0)); + let hour = match meridiem { + Some(_) if !(1..=12).contains(&hour) => { + return Err(format!("hour in {input:?} must be 1-12 with am/pm")); } + Some(true) => hour % 12 + 12, + Some(false) => hour % 12, None if hour > 23 => return Err(format!("hour in {input:?} must be 0-23")), - None => {} - } + None => hour, + }; jiff::civil::Time::new(hour as i8, minute as i8, second as i8, 0) .map_err(|e| format!("invalid time {input:?}: {e}")) } -- cgit v1.2.3