[pbs-devel] [PATCH v2 proxmox 2/5] time: also implement `From<&TimeSpan> for f64`
Christian Ebner
c.ebner at proxmox.com
Wed Oct 23 11:11:00 CEST 2024
Extend the already present `From<TimeSpan> 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 <c.ebner at proxmox.com>
---
changes since version 1:
- not present in previous version
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 ae311898..2e3ca99e 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<TimeSpan> 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<TimeSpan> for f64 {
}
}
+impl From<TimeSpan> for f64 {
+ fn from(ts: TimeSpan) -> Self {
+ Self::from(&ts)
+ }
+}
+
impl From<std::time::Duration> for TimeSpan {
fn from(duration: std::time::Duration) -> Self {
let mut duration = duration.as_nanos();
--
2.39.5
More information about the pbs-devel
mailing list