Skip to content

Commit

Permalink
migrate from once_cell::sync::Lazy to use std::sync::LazyLock
Browse files Browse the repository at this point in the history
  • Loading branch information
radhermit committed Oct 22, 2024
1 parent 1a5fcd9 commit ede8284
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 32 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ indexmap = { version = "2.6.0", features = ["serde"] }
indoc = "2.0.5"
itertools = "0.13.0"
libc = "0.2.161"
once_cell = "1.20.2"
serde = { version = "1.0.211", features = ["derive"] }
serde_json = "1.0.132"
serde_with = { version = "3.11.0", default-features = false, features = ["macros"] }
Expand Down
8 changes: 5 additions & 3 deletions crates/cli/tests/bite/bugzilla.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::env;
use std::sync::LazyLock;
use std::time::Duration;

use camino::Utf8PathBuf;
use once_cell::sync::Lazy;
use predicates::prelude::*;
use wiremock::{matchers, ResponseTemplate};

Expand All @@ -20,8 +20,10 @@ mod search;
mod update;
mod version;

static TEST_DATA: Lazy<Utf8PathBuf> = Lazy::new(|| crate::TEST_DATA_PATH.join("bugbite/bugzilla"));
static TEST_OUTPUT: Lazy<Utf8PathBuf> = Lazy::new(|| crate::TEST_DATA_PATH.join("output/bugzilla"));
static TEST_DATA: LazyLock<Utf8PathBuf> =
LazyLock::new(|| crate::TEST_DATA_PATH.join("bugbite/bugzilla"));
static TEST_OUTPUT: LazyLock<Utf8PathBuf> =
LazyLock::new(|| crate::TEST_DATA_PATH.join("output/bugzilla"));

#[test]
fn help() {
Expand Down
6 changes: 3 additions & 3 deletions crates/cli/tests/bite/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::sync::LazyLock;
use std::{env, fs};

use bugbite::test::{build_path, TestServer};
use camino::Utf8PathBuf;
use indexmap::IndexSet;
use itertools::Itertools;
use once_cell::sync::Lazy;
use predicates::prelude::*;
use tempfile::tempdir;

Expand All @@ -15,8 +15,8 @@ mod command;
mod redmine;
mod show;

pub(crate) static TEST_DATA_PATH: Lazy<Utf8PathBuf> =
Lazy::new(|| build_path!(env!("CARGO_MANIFEST_DIR"), "testdata"));
pub(crate) static TEST_DATA_PATH: LazyLock<Utf8PathBuf> =
LazyLock::new(|| build_path!(env!("CARGO_MANIFEST_DIR"), "testdata"));

async fn start_server() -> TestServer {
let server = TestServer::new().await;
Expand Down
6 changes: 4 additions & 2 deletions crates/cli/tests/bite/redmine.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::LazyLock;

use camino::Utf8PathBuf;
use once_cell::sync::Lazy;
use predicates::prelude::*;

use crate::command::cmd;
Expand All @@ -9,7 +10,8 @@ use super::*;
mod get;
mod search;

static TEST_DATA: Lazy<Utf8PathBuf> = Lazy::new(|| crate::TEST_DATA_PATH.join("bugbite/redmine"));
static TEST_DATA: LazyLock<Utf8PathBuf> =
LazyLock::new(|| crate::TEST_DATA_PATH.join("bugbite/redmine"));

#[test]
fn help() {
Expand Down
1 change: 0 additions & 1 deletion crates/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ humansize = "2.1.3"
infer = "0.16.0"
indexmap = { version = "2.6.0", features = ["serde"] }
itertools = "0.13.0"
once_cell = "1.20.2"
ordered-multimap = "0.7.3"
regex = "1.11.0"
serde = { version = "1.0.211", features = ["derive"] }
Expand Down
6 changes: 3 additions & 3 deletions crates/lib/src/objects.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::fmt;
use std::ops::RangeBounds;
use std::str::FromStr;
use std::sync::LazyLock;

use base64::prelude::*;
use once_cell::sync::Lazy;
use regex::Regex;
use serde_with::{DeserializeFromStr, SerializeDisplay};

Expand Down Expand Up @@ -151,8 +151,8 @@ impl<T: Eq> From<std::ops::RangeFull> for RangeOrValue<T> {
}
}

static RANGE_OP_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^(?<op>[<>]=?|!?=)(?<value>.+)$").unwrap());
static RANGE_OP_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^(?<op>[<>]=?|!?=)(?<value>.+)$").unwrap());

#[derive(DeserializeFromStr, SerializeDisplay, Debug, PartialEq, Eq, Clone)]
pub enum RangeOp<T: Eq> {
Expand Down
7 changes: 3 additions & 4 deletions crates/lib/src/output.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::borrow::Cow;
use std::cmp::Ordering;
use std::io::{self, IsTerminal, Write};
use std::sync::atomic::AtomicBool;
use std::sync::{atomic::AtomicBool, LazyLock};

use crossterm::terminal;
use futures_util::{pin_mut, Stream, TryStreamExt};
use itertools::Itertools;
use once_cell::sync::Lazy;
use serde::Serialize;
use unicode_segmentation::UnicodeSegmentation;

Expand All @@ -17,7 +16,7 @@ mod bugzilla;
mod github;
mod redmine;

pub static COLUMNS: Lazy<usize> = Lazy::new(|| {
pub static COLUMNS: LazyLock<usize> = LazyLock::new(|| {
let (cols, _rows) = terminal::size().unwrap_or((90, 24));
// use a static width when testing is enabled
if cfg!(feature = "test") {
Expand All @@ -28,7 +27,7 @@ pub static COLUMNS: Lazy<usize> = Lazy::new(|| {
});

// indentation for text-wrapping header field values
static INDENT: Lazy<String> = Lazy::new(|| " ".repeat(15));
static INDENT: LazyLock<String> = LazyLock::new(|| " ".repeat(15));

/// Control output verbosity.
pub static VERBOSE: AtomicBool = AtomicBool::new(false);
Expand Down
5 changes: 2 additions & 3 deletions crates/lib/src/service/bugzilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::collections::HashSet;
use std::fmt;
use std::ops::Deref;
use std::str::FromStr;
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

use indexmap::{IndexMap, IndexSet};
use once_cell::sync::Lazy;
use reqwest::RequestBuilder;
use serde::{Deserialize, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};
Expand All @@ -30,7 +29,7 @@ pub mod update;
pub mod version;

/// Common default values used for unset fields.
pub(crate) static UNSET_VALUES: Lazy<HashSet<String>> = Lazy::new(|| {
pub(crate) static UNSET_VALUES: LazyLock<HashSet<String>> = LazyLock::new(|| {
["unspecified", "Unspecified", "---", "--", "-", ""]
.iter()
.map(|s| s.to_string())
Expand Down
4 changes: 2 additions & 2 deletions crates/lib/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub fn reset_stdin() {
}

#[cfg(test)]
pub(crate) static TESTDATA_PATH: once_cell::sync::Lazy<camino::Utf8PathBuf> =
once_cell::sync::Lazy::new(|| build_path!(env!("CARGO_MANIFEST_DIR"), "testdata"));
pub(crate) static TESTDATA_PATH: std::sync::LazyLock<camino::Utf8PathBuf> =
std::sync::LazyLock::new(|| build_path!(env!("CARGO_MANIFEST_DIR"), "testdata"));

pub struct TestServer {
server: MockServer,
Expand Down
4 changes: 2 additions & 2 deletions crates/lib/src/test/bugzilla.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use once_cell::sync::Lazy;
use std::sync::LazyLock;

use crate::service::bugzilla::{Bugzilla, Config};

pub const BASE: &str = "http://127.0.0.1:8080/";
pub const USER: &str = "bugbite@bugbite.test";
pub const PASSWORD: &str = "bugbite";

pub static SERVICE: Lazy<Bugzilla> = Lazy::new(|| {
pub static SERVICE: LazyLock<Bugzilla> = LazyLock::new(|| {
let mut config = Config::new(BASE).unwrap();
config.auth.user = Some(USER.to_string());
config.auth.password = Some(PASSWORD.to_string());
Expand Down
6 changes: 3 additions & 3 deletions crates/lib/src/time/delta.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use std::fmt;
use std::str::FromStr;
use std::sync::LazyLock;

use chrono::offset::Utc;
use chronoutil::RelativeDuration;
use once_cell::sync::Lazy;
use regex::Regex;
use serde_with::{DeserializeFromStr, SerializeDisplay};

use crate::traits::Api;
use crate::Error;

static RELATIVE_TIME_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^(?<value>\d+)(?<unit>[[:alpha:]]+)$").unwrap());
static RELATIVE_TIME_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^(?<value>\d+)(?<unit>[[:alpha:]]+)$").unwrap());

#[derive(DeserializeFromStr, SerializeDisplay, Debug, Clone, PartialEq, Eq)]
pub struct TimeDelta {
Expand Down
6 changes: 3 additions & 3 deletions crates/lib/src/time/static.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::fmt;
use std::str::FromStr;
use std::sync::LazyLock;

use chrono::{offset::Utc, DateTime, NaiveDate, NaiveTime};
use once_cell::sync::Lazy;
use regex::Regex;
use serde_with::{DeserializeFromStr, SerializeDisplay};

use crate::traits::Api;
use crate::Error;

static STATIC_DATE_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^(?<year>\d\d\d\d)(-(?<month>\d\d))?(-(?<day>\d\d))?$").unwrap());
static STATIC_DATE_RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^(?<year>\d\d\d\d)(-(?<month>\d\d))?(-(?<day>\d\d))?$").unwrap());

#[derive(DeserializeFromStr, SerializeDisplay, Debug, Clone, PartialEq, Eq)]
pub struct TimeStatic {
Expand Down

0 comments on commit ede8284

Please sign in to comment.