Skip to content

Commit

Permalink
Fully switch from once_cell to std lazy types
Browse files Browse the repository at this point in the history
  • Loading branch information
mgziminsky committed Sep 12, 2024
1 parent 705f3fb commit 1adf43a
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 19 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ anyhow = "1.0"
async-scoped = { version = "0.9", features = ["use-tokio"] }
dirs = "5"
itertools = "0.13"
once_cell = "1.19"
reqwest = { version = "0.12", default-features = false }
serde = "1.0"
serde_json = "1.0"
Expand Down
1 change: 0 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ anyhow.workspace = true
async-scoped.workspace = true
dirs.workspace = true
itertools.workspace = true
once_cell.workspace = true
reqwest = { workspace = true, features = ["rustls-tls"] }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
Expand Down
5 changes: 2 additions & 3 deletions cli/src/file_picker.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::path::{Path, PathBuf};
use std::{path::{Path, PathBuf}, sync::LazyLock};

use once_cell::sync::Lazy;

static HOME: Lazy<PathBuf> = Lazy::new(|| dirs::home_dir().expect("should be able to determine home dir"));
static HOME: LazyLock<PathBuf> = LazyLock::new(|| dirs::home_dir().expect("should be able to determine home dir"));

/// Use the system file picker to pick a file, with a `default` path (that is [not supported on linux](https://github.com/PolyMeilex/rfd/issues/42))
#[cfg(any(feature = "gui", ide))]
Expand Down
5 changes: 2 additions & 3 deletions cli/src/subcommands/mods/list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{collections::HashMap, ops::Deref};
use std::{collections::HashMap, ops::Deref, sync::LazyLock};

use anyhow::{Context, Result};
use once_cell::sync::Lazy;
use relibium::{
client::schema::{Author, ProjectId, ProjectIdSvcType},
config::{Mod, Profile, VersionedProject},
Expand All @@ -12,7 +11,7 @@ use yansi::Paint;

use crate::tui::{print_mods, print_project_markdown, print_project_verbose};

static MR_BASE: Lazy<::url::Url> = Lazy::new(|| {
static MR_BASE: LazyLock<::url::Url> = LazyLock::new(|| {
"https://modrinth.com/user/"
.parse()
.expect("base url should always parse successfully")
Expand Down
1 change: 0 additions & 1 deletion lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ anyhow.workspace = true
async-scoped.workspace = true
dirs.workspace = true
itertools.workspace = true
once_cell.workspace = true
reqwest = { workspace = true, features = ["rustls-tls"] }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
Expand Down
5 changes: 3 additions & 2 deletions lib/src/client/curseforge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ async fn fetch_mods(client: &ForgeClient, mod_ids: Vec<u64>) -> Result<Vec<curse
}

mod from {
use std::sync::LazyLock;

use curseforge::{
models::{File, FileDependency, FileRelationType, HashAlgo, MinecraftGameVersion, ModAuthor, ModLoaderType},
Error as ApiError, ErrorResponse,
};
use once_cell::sync::Lazy;
use reqwest::StatusCode;
use url::Url;

Expand All @@ -204,7 +205,7 @@ mod from {
pub const MOD_CLASS_ID: u64 = 6;
pub const MODPACK_CLASS_ID: u64 = 4471;

static HOME: Lazy<Url> = Lazy::new(|| {
static HOME: LazyLock<Url> = LazyLock::new(|| {
"https://www.curseforge.com/minecraft/"
.parse()
.expect("base url should always parse successfully")
Expand Down
5 changes: 3 additions & 2 deletions lib/src/client/modrinth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,15 @@ async fn fetch_project(client: &ModrinthClient, mod_id: &str) -> Result<ApiProje
}

mod from {
use std::sync::LazyLock;

use modrinth::{
models::{
project::ProjectType, version_dependency::DependencyType as ModrinthDepType, GameVersionTag, Project as ApiProject,
ProjectLicense, Version as ApiVersion, VersionDependency,
},
Error as ApiError, ErrorResponse,
};
use once_cell::sync::Lazy;
use reqwest::StatusCode;
use url::Url;

Expand All @@ -206,7 +207,7 @@ mod from {
ErrorKind,
};

static HOME: Lazy<Url> = Lazy::new(|| "https://modrinth.com/".parse().expect("base url should always parse successfully"));
static HOME: LazyLock<Url> = LazyLock::new(|| "https://modrinth.com/".parse().expect("base url should always parse successfully"));

impl From<ModrinthClient> for Client {
fn from(value: ModrinthClient) -> Self {
Expand Down
7 changes: 3 additions & 4 deletions lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ mod serde;
#[doc = "Types relating to [profile data](profile::ProfileData)\n\n"]
pub mod profile;

use std::{collections::BTreeSet, path::Path};
use std::{collections::BTreeSet, path::Path, sync::LazyLock};

use ::serde::{Deserialize, Serialize};
use once_cell::sync::Lazy;

#[doc(inline)]
pub use self::profile::Profile;
Expand All @@ -25,7 +24,7 @@ use crate::{
};

/// Full path to the default config file
pub static DEFAULT_CONFIG_PATH: Lazy<PathAbsolute> = Lazy::new(|| CONF_DIR.join("config.json"));
pub static DEFAULT_CONFIG_PATH: LazyLock<PathAbsolute> = LazyLock::new(|| CONF_DIR.join("config.json"));

type ProfilesList = BTreeSet<ProfileByPath>;

Expand Down Expand Up @@ -272,7 +271,7 @@ mod tests {

use super::*;

static PATHS: Lazy<[PathAbsolute; 3]> = Lazy::new(|| {
static PATHS: LazyLock<[PathAbsolute; 3]> = LazyLock::new(|| {
[
PathAbsolute::new("/test/profile/path/1").unwrap(),
PathAbsolute::new("/test/profile/path/2").unwrap(),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/mgmt/cache.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use once_cell::sync::Lazy;
use std::sync::LazyLock;

use crate::{
checked_types::{PathAbsolute, PathScopedRef},
Expand All @@ -8,7 +8,7 @@ use crate::{

/// The base path where files are downloaded to before they are copied into a
/// profile
pub static CACHE_DIR: Lazy<PathAbsolute> = Lazy::new(|| {
pub static CACHE_DIR: LazyLock<PathAbsolute> = LazyLock::new(|| {
dirs::cache_dir()
.expect("system cache directory should be known")
.join(concat!(env!("CARGO_PKG_NAME"), "-cache"))
Expand Down

0 comments on commit 1adf43a

Please sign in to comment.