From 17bc0ac616c3c97c3ed4ab8a6861bb9f93e040b2 Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Wed, 23 Oct 2024 11:11:00 +0200 Subject: [PATCH] time: also implement `From<&TimeSpan> for f64` Extend the already present `From for f64` implementation to allow using the reference as well. There is no need to take ownership and consume the `TimeSpan` object for conversion. Signed-off-by: Christian Ebner --- proxmox-time/src/time_span.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/proxmox-time/src/time_span.rs b/proxmox-time/src/time_span.rs index 9eea3f28..6081a534 100644 --- a/proxmox-time/src/time_span.rs +++ b/proxmox-time/src/time_span.rs @@ -128,8 +128,8 @@ pub struct TimeSpan { pub years: u64, } -impl From for f64 { - fn from(ts: TimeSpan) -> Self { +impl From<&TimeSpan> for f64 { + fn from(ts: &TimeSpan) -> Self { (ts.seconds as f64) + ((ts.nsec as f64) / 1_000_000_000.0) + ((ts.usec as f64) / 1_000_000.0) @@ -143,6 +143,12 @@ impl From for f64 { } } +impl From for f64 { + fn from(ts: TimeSpan) -> Self { + Self::from(&ts) + } +} + impl From for TimeSpan { fn from(duration: std::time::Duration) -> Self { let mut duration = duration.as_nanos();