Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to LazyLock from std (Rust 1.80) #2074

Merged
merged 2 commits into from
Aug 13, 2024
Merged

switch to LazyLock from std (Rust 1.80) #2074

merged 2 commits into from
Aug 13, 2024

Conversation

MaxVerevkin
Copy link
Collaborator

No description provided.

@bim9262
Copy link
Collaborator

bim9262 commented Aug 11, 2024

@MaxVerevkin , this looks good to me, but I'd probably not alias LazyLock to Lazy in the prelude:

Like this
diff --git a/src/blocks/packages/pacman.rs b/src/blocks/packages/pacman.rs
index 0f74dc963..fc4da0935 100644
--- a/src/blocks/packages/pacman.rs
+++ b/src/blocks/packages/pacman.rs
@@ -10,7 +10,7 @@ use crate::util::has_command;
 
 make_log_macro!(debug, "pacman");
 
-pub static PACMAN_UPDATES_DB: Lazy<PathBuf> = Lazy::new(|| {
+pub static PACMAN_UPDATES_DB: LazyLock<PathBuf> = LazyLock::new(|| {
     let path = match env::var_os("CHECKUPDATES_DB") {
         Some(val) => val.into(),
         None => {
@@ -27,7 +27,7 @@ pub static PACMAN_UPDATES_DB: Lazy<PathBuf> = Lazy::new(|| {
     path
 });
 
-pub static PACMAN_DB: Lazy<PathBuf> = Lazy::new(|| {
+pub static PACMAN_DB: LazyLock<PathBuf> = LazyLock::new(|| {
     let path = env::var_os("DBPath")
         .map(Into::into)
         .unwrap_or_else(|| PathBuf::from("/var/lib/pacman/"));
diff --git a/src/blocks/prelude.rs b/src/blocks/prelude.rs
index e8bf8d7a8..3b587000b 100644
--- a/src/blocks/prelude.rs
+++ b/src/blocks/prelude.rs
@@ -17,7 +17,7 @@ pub use std::borrow::Cow;
 pub use std::collections::HashMap;
 pub use std::fmt::Write;
 pub use std::pin::Pin;
-pub use std::sync::LazyLock as Lazy;
+pub use std::sync::LazyLock;
 pub use std::time::Duration;
 
 pub use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncReadExt, AsyncWriteExt};
diff --git a/src/blocks/privacy/pipewire.rs b/src/blocks/privacy/pipewire.rs
index ce575f9b5..fac790901 100644
--- a/src/blocks/privacy/pipewire.rs
+++ b/src/blocks/privacy/pipewire.rs
@@ -13,7 +13,7 @@ use tokio::sync::Notify;
 
 use super::*;
 
-static CLIENT: Lazy<Result<Client>> = Lazy::new(Client::new);
+static CLIENT: LazyLock<Result<Client>> = LazyLock::new(Client::new);
 
 #[derive(Debug)]
 struct Node {
diff --git a/src/blocks/sound/pulseaudio.rs b/src/blocks/sound/pulseaudio.rs
index e61ad6893..c0e5334e3 100644
--- a/src/blocks/sound/pulseaudio.rs
+++ b/src/blocks/sound/pulseaudio.rs
@@ -20,9 +20,9 @@ use tokio::sync::Notify;
 use super::super::prelude::*;
 use super::{DeviceKind, SoundDevice};
 
-static CLIENT: Lazy<Result<Client>> = Lazy::new(Client::new);
+static CLIENT: LazyLock<Result<Client>> = LazyLock::new(Client::new);
 static EVENT_LISTENER: Mutex<Vec<Weak<Notify>>> = Mutex::new(Vec::new());
-static DEVICES: Lazy<Mutex<HashMap<(DeviceKind, String), VolInfo>>> = Lazy::new(default);
+static DEVICES: LazyLock<Mutex<HashMap<(DeviceKind, String), VolInfo>>> = LazyLock::new(default);
 
 // Default device names
 pub(super) static DEFAULT_SOURCE: Mutex<Cow<'static, str>> =
diff --git a/src/blocks/weather/met_no.rs b/src/blocks/weather/met_no.rs
index eacf704cc..4babd4e1a 100644
--- a/src/blocks/weather/met_no.rs
+++ b/src/blocks/weather/met_no.rs
@@ -129,8 +129,8 @@ struct ForecastTimeInstant {
     relative_humidity: Option<f64>,
 }
 
-static LEGENDS: Lazy<Option<LegendsStore>> =
-    Lazy::new(|| serde_json::from_str(include_str!("met_no_legends.json")).ok());
+static LEGENDS: LazyLock<Option<LegendsStore>> =
+    LazyLock::new(|| serde_json::from_str(include_str!("met_no_legends.json")).ok());
 
 const FORECAST_URL: &str = "https://api.met.no/weatherapi/locationforecast/2.0/compact";
 

@MaxVerevkin MaxVerevkin marked this pull request as ready for review August 13, 2024 18:08
@MaxVerevkin MaxVerevkin merged commit a155a6b into master Aug 13, 2024
26 checks passed
@MaxVerevkin MaxVerevkin deleted the r80 branch August 13, 2024 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants