public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Maximiliano Sandoval <m.sandoval@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 06/12] time: remove lazy_static dependency
Date: Tue, 13 Aug 2024 12:57:03 +0200	[thread overview]
Message-ID: <20240813105709.320119-6-m.sandoval@proxmox.com> (raw)
In-Reply-To: <20240813105709.320119-1-m.sandoval@proxmox.com>

Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
---
 proxmox-time/Cargo.toml       |  2 +-
 proxmox-time/debian/control   |  2 -
 proxmox-time/src/time_span.rs | 94 +++++++++++++++++------------------
 3 files changed, 47 insertions(+), 51 deletions(-)

diff --git a/proxmox-time/Cargo.toml b/proxmox-time/Cargo.toml
index 17282507..d863fa0c 100644
--- a/proxmox-time/Cargo.toml
+++ b/proxmox-time/Cargo.toml
@@ -6,13 +6,13 @@ edition.workspace = true
 license.workspace = true
 repository.workspace = true
 description = "time utilities and TmEditor"
+rust-version.workspace = true
 
 exclude.workspace = true
 
 [dependencies]
 anyhow.workspace = true
 bitflags.workspace = true
-lazy_static.workspace = true
 nom = "7"
 
 [target.'cfg(not(target_arch="wasm32"))'.dependencies]
diff --git a/proxmox-time/debian/control b/proxmox-time/debian/control
index 5576ddcb..1eecc944 100644
--- a/proxmox-time/debian/control
+++ b/proxmox-time/debian/control
@@ -9,7 +9,6 @@ Build-Depends: debhelper (>= 12),
  librust-anyhow-1+default-dev <!nocheck>,
  librust-bitflags-2+default-dev (>= 2.4-~~) <!nocheck>,
  librust-js-sys-0.3+default-dev (>= 0.3.55-~~) <!nocheck>,
- librust-lazy-static-1+default-dev (>= 1.4-~~) <!nocheck>,
  librust-libc-0.2+default-dev (>= 0.2.107-~~) <!nocheck>,
  librust-libc-0.2+extra-traits-dev (>= 0.2.107-~~) <!nocheck>,
  librust-nom-7+default-dev <!nocheck>
@@ -29,7 +28,6 @@ Depends:
  librust-bitflags-2+default-dev (>= 2.4-~~),
  librust-js-sys-0.3+default-dev (>= 0.3.55-~~),
  librust-lazy-static-1+default-dev (>= 1.4-~~),
- librust-libc-0.2+default-dev (>= 0.2.107-~~),
  librust-libc-0.2+extra-traits-dev (>= 0.2.107-~~),
  librust-nom-7+default-dev
 Provides:
diff --git a/proxmox-time/src/time_span.rs b/proxmox-time/src/time_span.rs
index e580c3d6..2ccdf08b 100644
--- a/proxmox-time/src/time_span.rs
+++ b/proxmox-time/src/time_span.rs
@@ -1,79 +1,77 @@
 use std::collections::HashMap;
+use std::sync::LazyLock;
 
 use anyhow::Error;
-use lazy_static::lazy_static;
 use nom::{bytes::complete::take_while1, character::complete::space0, combinator::opt};
 
 use crate::parse_helpers::{parse_complete_line, parse_error, parse_u64, IResult};
 
-lazy_static! {
-    static ref TIME_SPAN_UNITS: HashMap<&'static str, f64> = {
-        let mut map = HashMap::new();
+static TIME_SPAN_UNITS: LazyLock<HashMap<&'static str, f64>> = LazyLock::new(|| {
+    let mut map = HashMap::new();
 
-        let second = 1.0;
+    let second = 1.0;
 
-        map.insert("seconds", second);
-        map.insert("second", second);
-        map.insert("sec", second);
-        map.insert("s", second);
+    map.insert("seconds", second);
+    map.insert("second", second);
+    map.insert("sec", second);
+    map.insert("s", second);
 
-        let msec = second / 1000.0;
+    let msec = second / 1000.0;
 
-        map.insert("msec", msec);
-        map.insert("ms", msec);
+    map.insert("msec", msec);
+    map.insert("ms", msec);
 
-        let usec = msec / 1000.0;
+    let usec = msec / 1000.0;
 
-        map.insert("usec", usec);
-        map.insert("us", usec);
-        map.insert("µs", usec);
+    map.insert("usec", usec);
+    map.insert("us", usec);
+    map.insert("µs", usec);
 
-        let nsec = usec / 1000.0;
+    let nsec = usec / 1000.0;
 
-        map.insert("nsec", nsec);
-        map.insert("ns", nsec);
+    map.insert("nsec", nsec);
+    map.insert("ns", nsec);
 
-        let minute = second * 60.0;
+    let minute = second * 60.0;
 
-        map.insert("minutes", minute);
-        map.insert("minute", minute);
-        map.insert("min", minute);
-        map.insert("m", minute);
+    map.insert("minutes", minute);
+    map.insert("minute", minute);
+    map.insert("min", minute);
+    map.insert("m", minute);
 
-        let hour = minute * 60.0;
+    let hour = minute * 60.0;
 
-        map.insert("hours", hour);
-        map.insert("hour", hour);
-        map.insert("hr", hour);
-        map.insert("h", hour);
+    map.insert("hours", hour);
+    map.insert("hour", hour);
+    map.insert("hr", hour);
+    map.insert("h", hour);
 
-        let day = hour * 24.0;
+    let day = hour * 24.0;
 
-        map.insert("days", day);
-        map.insert("day", day);
-        map.insert("d", day);
+    map.insert("days", day);
+    map.insert("day", day);
+    map.insert("d", day);
 
-        let week = day * 7.0;
+    let week = day * 7.0;
 
-        map.insert("weeks", week);
-        map.insert("week", week);
-        map.insert("w", week);
+    map.insert("weeks", week);
+    map.insert("week", week);
+    map.insert("w", week);
 
-        let month = 30.44 * day;
+    let month = 30.44 * day;
 
-        map.insert("months", month);
-        map.insert("month", month);
-        map.insert("M", month);
+    map.insert("months", month);
+    map.insert("month", month);
+    map.insert("M", month);
 
-        let year = 365.25 * day;
+    let year = 365.25 * day;
 
-        map.insert("years", year);
-        map.insert("year", year);
-        map.insert("y", year);
+    map.insert("years", year);
+    map.insert("year", year);
+    map.insert("y", year);
 
-        map
-    };
-}
+    map
+});
 
 /// A time spans defines a time duration
 #[derive(Default, Clone, Debug)]
-- 
2.39.2



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel

  parent reply	other threads:[~2024-08-13 10:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-13 10:56 [pbs-devel] [PATCH proxmox 01/12] cargo: set msrv to 1.80 Maximiliano Sandoval
2024-08-13 10:56 ` [pbs-devel] [PATCH proxmox 02/12] dns-api: remove lazy-static dependency Maximiliano Sandoval
2024-08-13 10:57 ` [pbs-devel] [PATCH proxmox 03/12] async: remove lazy_static dependency Maximiliano Sandoval
2024-08-13 10:57 ` [pbs-devel] [PATCH proxmox 04/12] subscription: " Maximiliano Sandoval
2024-08-13 10:57 ` [pbs-devel] [PATCH proxmox 05/12] rest-server: " Maximiliano Sandoval
2024-08-13 10:57 ` Maximiliano Sandoval [this message]
2024-08-13 10:57 ` [pbs-devel] [PATCH proxmox 07/12] sys: " Maximiliano Sandoval
2024-08-13 10:57 ` [pbs-devel] [PATCH proxmox 08/12] network-api: " Maximiliano Sandoval
2024-08-13 10:57 ` [pbs-devel] [PATCH proxmox 09/12] auth-api: " Maximiliano Sandoval
2024-08-13 10:57 ` [pbs-devel] [PATCH proxmox 10/12] acme-api: " Maximiliano Sandoval
2024-08-13 10:57 ` [pbs-devel] [PATCH proxmox 11/12] schema: " Maximiliano Sandoval
2024-08-13 10:57 ` [pbs-devel] [PATCH proxmox 12/12] cargo: remove lazy_static dependency on workspace Maximiliano Sandoval

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240813105709.320119-6-m.sandoval@proxmox.com \
    --to=m.sandoval@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal