Skip to content

Commit 5e66716

Browse files
committed
Replace lazy_static with LazyLock
1 parent a9ed2b9 commit 5e66716

File tree

6 files changed

+19
-35
lines changed

6 files changed

+19
-35
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
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
@@ -12,7 +12,6 @@ openssl = "0.10"
1212
dotenv = "0.15"
1313
reqwest = { version = "0.11.4", features = ["json", "blocking"] }
1414
regex = "1"
15-
lazy_static = "1"
1615
anyhow = "1"
1716
hex = "0.4"
1817
parser = { path = "parser" }

src/actions.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use chrono::{DateTime, Utc};
22
use std::collections::HashMap;
3-
use std::sync::Arc;
3+
use std::sync::{Arc, LazyLock};
44

55
use async_trait::async_trait;
66
use serde::{Deserialize, Serialize};
@@ -83,17 +83,13 @@ pub struct MCPDetails {
8383
pub concerns: Option<Vec<(String, String)>>,
8484
}
8585

86-
lazy_static! {
87-
pub static ref TEMPLATES: Tera = {
88-
match Tera::new("templates/*") {
89-
Ok(t) => t,
90-
Err(e) => {
91-
println!("Parsing error(s): {}", e);
92-
::std::process::exit(1);
93-
}
94-
}
95-
};
96-
}
86+
pub static TEMPLATES: LazyLock<Tera> = LazyLock::new(|| match Tera::new("templates/*") {
87+
Ok(t) => t,
88+
Err(e) => {
89+
println!("Parsing error(s): {}", e);
90+
::std::process::exit(1);
91+
}
92+
});
9793

9894
pub fn to_human(d: DateTime<Utc>) -> String {
9995
let d1 = chrono::Utc::now() - d;

src/config.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ use crate::changelogs::ChangelogFormat;
22
use crate::github::{GithubClient, Repository};
33
use std::collections::{HashMap, HashSet};
44
use std::fmt;
5-
use std::sync::{Arc, RwLock};
5+
use std::sync::{Arc, LazyLock, RwLock};
66
use std::time::{Duration, Instant};
77
use tracing as log;
88

99
pub(crate) static CONFIG_FILE_NAME: &str = "triagebot.toml";
1010
const REFRESH_EVERY: Duration = Duration::from_secs(2 * 60); // Every two minutes
1111

12-
lazy_static::lazy_static! {
13-
static ref CONFIG_CACHE:
14-
RwLock<HashMap<String, (Result<Arc<Config>, ConfigurationError>, Instant)>> =
15-
RwLock::new(HashMap::new());
16-
}
12+
static CONFIG_CACHE: LazyLock<
13+
RwLock<HashMap<String, (Result<Arc<Config>, ConfigurationError>, Instant)>>,
14+
> = LazyLock::new(|| RwLock::new(HashMap::new()));
1715

1816
// This struct maps each possible option of the triagebot.toml.
1917
// See documentation of options at: https://forge.rust-lang.org/triagebot/pr-assignment.html#configuration

src/db.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use anyhow::Context as _;
33
use chrono::Utc;
44
use native_tls::{Certificate, TlsConnector};
55
use postgres_native_tls::MakeTlsConnector;
6-
use std::sync::{Arc, Mutex};
6+
use std::sync::{Arc, LazyLock, Mutex};
77
use tokio::sync::{OwnedSemaphorePermit, Semaphore};
88
use tokio_postgres::Client as DbClient;
99

@@ -14,16 +14,11 @@ pub mod rustc_commits;
1414

1515
const CERT_URL: &str = "https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem";
1616

17-
lazy_static::lazy_static! {
18-
static ref CERTIFICATE_PEMS: Vec<u8> = {
19-
let client = reqwest::blocking::Client::new();
20-
let resp = client
21-
.get(CERT_URL)
22-
.send()
23-
.expect("failed to get RDS cert");
24-
resp.bytes().expect("failed to get RDS cert body").to_vec()
25-
};
26-
}
17+
static CERTIFICATE_PEMS: LazyLock<Vec<u8>> = LazyLock::new(|| {
18+
let client = reqwest::blocking::Client::new();
19+
let resp = client.get(CERT_URL).send().expect("failed to get RDS cert");
20+
resp.bytes().expect("failed to get RDS cert body").to_vec()
21+
});
2722

2823
pub struct ClientPool {
2924
connections: Arc<Mutex<Vec<tokio_postgres::Client>>>,

src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#![allow(clippy::new_without_default)]
22

3-
#[macro_use]
4-
extern crate lazy_static;
5-
63
use crate::github::PullRequestDetails;
74

85
use anyhow::Context;

0 commit comments

Comments
 (0)