Skip to content

Commit a155a6b

Browse files
authored
switch to LazyLock from std (Rust 1.80) (#2074)
* fix clippy lint * switch to LazyLock from std
1 parent 04188c2 commit a155a6b

File tree

11 files changed

+16
-20
lines changed

11 files changed

+16
-20
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ neli-wifi = { version = "0.6", features = ["async"] }
5757
nix = { version = "0.28", features = ["fs", "process"] }
5858
nom = "7.1.2"
5959
notmuch = { version = "0.8", optional = true }
60-
once_cell = "1"
6160
pipewire = { version = "0.8", default-features = false, optional = true }
6261
regex = "1.5"
6362
reqwest = { version = "0.11", features = ["json"] }

src/blocks/packages/pacman.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::util::has_command;
1010

1111
make_log_macro!(debug, "pacman");
1212

13-
pub static PACMAN_UPDATES_DB: Lazy<PathBuf> = Lazy::new(|| {
13+
pub static PACMAN_UPDATES_DB: LazyLock<PathBuf> = LazyLock::new(|| {
1414
let path = match env::var_os("CHECKUPDATES_DB") {
1515
Some(val) => val.into(),
1616
None => {
@@ -27,7 +27,7 @@ pub static PACMAN_UPDATES_DB: Lazy<PathBuf> = Lazy::new(|| {
2727
path
2828
});
2929

30-
pub static PACMAN_DB: Lazy<PathBuf> = Lazy::new(|| {
30+
pub static PACMAN_DB: LazyLock<PathBuf> = LazyLock::new(|| {
3131
let path = env::var_os("DBPath")
3232
.map(Into::into)
3333
.unwrap_or_else(|| PathBuf::from("/var/lib/pacman/"));

src/blocks/prelude.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub use std::borrow::Cow;
1717
pub use std::collections::HashMap;
1818
pub use std::fmt::Write;
1919
pub use std::pin::Pin;
20+
pub use std::sync::LazyLock;
2021
pub use std::time::Duration;
2122

2223
pub use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncReadExt, AsyncWriteExt};
@@ -25,8 +26,6 @@ pub use tokio::time::sleep;
2526

2627
pub use futures::{Stream, StreamExt};
2728

28-
pub use once_cell::sync::Lazy;
29-
3029
pub use smart_default::SmartDefault;
3130

3231
pub use async_trait::async_trait;

src/blocks/privacy/pipewire.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tokio::sync::Notify;
1313

1414
use super::*;
1515

16-
static CLIENT: Lazy<Result<Client>> = Lazy::new(Client::new);
16+
static CLIENT: LazyLock<Result<Client>> = LazyLock::new(Client::new);
1717

1818
#[derive(Debug)]
1919
struct Node {

src/blocks/rofication.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ async fn rofication_status(socket_path: &str) -> Result<(usize, usize)> {
9595

9696
// Response must be two integers: regular and critical, separated either by a comma or a \n
9797
let (num, crit) = response
98-
.split_once(|x| x == ',' || x == '\n')
98+
.split_once([',', '\n'])
9999
.error("Incorrect response")?;
100100
Ok((
101101
num.parse().error("Incorrect response")?,

src/blocks/sound/pulseaudio.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use tokio::sync::Notify;
2020
use super::super::prelude::*;
2121
use super::{DeviceKind, SoundDevice};
2222

23-
static CLIENT: Lazy<Result<Client>> = Lazy::new(Client::new);
23+
static CLIENT: LazyLock<Result<Client>> = LazyLock::new(Client::new);
2424
static EVENT_LISTENER: Mutex<Vec<Weak<Notify>>> = Mutex::new(Vec::new());
25-
static DEVICES: Lazy<Mutex<HashMap<(DeviceKind, String), VolInfo>>> = Lazy::new(default);
25+
static DEVICES: LazyLock<Mutex<HashMap<(DeviceKind, String), VolInfo>>> = LazyLock::new(default);
2626

2727
// Default device names
2828
pub(super) static DEFAULT_SOURCE: Mutex<Cow<'static, str>> =

src/blocks/weather/met_no.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ struct ForecastTimeInstant {
171171
relative_humidity: Option<f64>,
172172
}
173173

174-
static LEGENDS: Lazy<Option<LegendsStore>> =
175-
Lazy::new(|| serde_json::from_str(include_str!("met_no_legends.json")).ok());
174+
static LEGENDS: LazyLock<Option<LegendsStore>> =
175+
LazyLock::new(|| serde_json::from_str(include_str!("met_no_legends.json")).ok());
176176

177177
const FORECAST_URL: &str = "https://api.met.no/weatherapi/locationforecast/2.0/compact";
178178

src/formatting/formatter/datetime.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
use chrono::format::{Fixed, Item, StrftimeItems};
22
use chrono::{DateTime, Datelike, Local, LocalResult, Locale, TimeZone, Timelike};
33
use chrono_tz::{OffsetName, Tz};
4-
use once_cell::sync::Lazy;
54

65
use std::fmt::Display;
6+
use std::sync::LazyLock;
77

88
use super::*;
99

1010
make_log_macro!(error, "datetime");
1111

1212
const DEFAULT_DATETIME_FORMAT: &str = "%a %d/%m %R";
1313

14-
pub static DEFAULT_DATETIME_FORMATTER: Lazy<DatetimeFormatter> =
15-
Lazy::new(|| DatetimeFormatter::new(Some(DEFAULT_DATETIME_FORMAT), None).unwrap());
14+
pub static DEFAULT_DATETIME_FORMATTER: LazyLock<DatetimeFormatter> =
15+
LazyLock::new(|| DatetimeFormatter::new(Some(DEFAULT_DATETIME_FORMAT), None).unwrap());
1616

1717
#[derive(Debug)]
1818
pub enum DatetimeFormatter {

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ pub use tokio;
2828
use std::borrow::Cow;
2929
use std::future::Future;
3030
use std::pin::Pin;
31-
use std::sync::Arc;
31+
use std::sync::{Arc, LazyLock};
3232
use std::time::Duration;
3333

3434
use futures::stream::{FuturesUnordered, StreamExt};
3535
use futures::Stream;
36-
use once_cell::sync::Lazy;
3736
use tokio::process::Command;
3837
use tokio::sync::{mpsc, Notify};
3938

@@ -51,15 +50,15 @@ use crate::widget::{State, Widget};
5150
const APP_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
5251
const REQWEST_TIMEOUT: Duration = Duration::from_secs(10);
5352

54-
static REQWEST_CLIENT: Lazy<reqwest::Client> = Lazy::new(|| {
53+
static REQWEST_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| {
5554
reqwest::Client::builder()
5655
.user_agent(APP_USER_AGENT)
5756
.timeout(REQWEST_TIMEOUT)
5857
.build()
5958
.unwrap()
6059
});
6160

62-
static REQWEST_CLIENT_IPV4: Lazy<reqwest::Client> = Lazy::new(|| {
61+
static REQWEST_CLIENT_IPV4: LazyLock<reqwest::Client> = LazyLock::new(|| {
6362
reqwest::Client::builder()
6463
.user_agent(APP_USER_AGENT)
6564
.local_address(Some(std::net::Ipv4Addr::UNSPECIFIED.into()))

0 commit comments

Comments
 (0)