Skip to content

Commit c195028

Browse files
Switch to once_cell
1 parent 005bf7f commit c195028

File tree

6 files changed

+25
-27
lines changed

6 files changed

+25
-27
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ferium"
3-
version = "4.3.0"
3+
version = "4.3.1"
44
edition = "2021"
55
rust-version = "1.61" # Bound by `std::process::ExitCode`
66
authors = [
@@ -9,7 +9,10 @@ authors = [
99
"Daniel Hauck (SolidTux)",
1010
]
1111
description = "Fast CLI program for managing Minecraft mods and modpacks from Modrinth, CurseForge, and Github Releases"
12-
exclude = ["tests", "media"] # Don't need tests and media for installing using crates.io
12+
exclude = [
13+
"tests",
14+
"media",
15+
] # Don't need tests and media for installing using crates.io
1316
repository = "https://github.com/gorilla-devs/ferium"
1417
categories = ["command-line-utilities"]
1518
readme = "README.md"
@@ -34,11 +37,11 @@ tokio = { version = "1.23", default-features = false, features = [
3437
] }
3538
clap = { version = "4.0", features = ["derive"] }
3639
clap_complete = "4.0"
37-
lazy_static = "1.4"
3840
serde_json = "1.0"
3941
dialoguer = "0.10"
4042
indicatif = "0.17"
4143
itertools = "0.10"
44+
once_cell = "1.16"
4245
fs_extra = "1.2"
4346
colored = "2.0"
4447
ferinth = "2.7"

src/download.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{style_byte, TICK};
1+
use crate::{STYLE_BYTE, TICK};
22
use anyhow::{anyhow, bail, Error, Result};
33
use colored::Colorize;
44
use fs_extra::{
@@ -19,7 +19,6 @@ use std::{
1919
};
2020
use tokio::{
2121
fs::{copy, create_dir_all, remove_file},
22-
2322
sync::Semaphore,
2423
task::JoinSet,
2524
};
@@ -110,7 +109,7 @@ pub async fn download(
110109
.map(|downloadable| downloadable.length)
111110
.sum(),
112111
)
113-
.with_style(style_byte()),
112+
.with_style(STYLE_BYTE.clone()),
114113
));
115114
progress_bar
116115
.force_lock()

src/main.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use dialoguer::theme::ColorfulTheme;
1010
use ferinth::Ferinth;
1111
use furse::Furse;
1212
use indicatif::ProgressStyle;
13-
use lazy_static::lazy_static;
1413
use libium::config::{
1514
self,
1615
structs::{Config, ModIdentifier, Modpack, Profile},
1716
};
1817
use octocrab::OctocrabBuilder;
18+
use once_cell::sync::Lazy;
1919
use online::tokio::check;
2020
use std::{
2121
env::{var, var_os},
@@ -25,29 +25,25 @@ use std::{
2525
use tokio::{runtime, task::JoinSet};
2626

2727
const CROSS: &str = "×";
28-
lazy_static! {
29-
pub static ref TICK: ColoredString = "✓".green();
30-
pub static ref YELLOW_TICK: ColoredString = "✓".yellow();
31-
pub static ref THEME: ColorfulTheme = ColorfulTheme::default();
32-
}
33-
28+
pub static TICK: Lazy<ColoredString> = Lazy::new(|| "✓".green());
29+
pub static YELLOW_TICK: Lazy<ColoredString> = Lazy::new(|| "✓".yellow());
30+
pub static THEME: Lazy<ColorfulTheme> = Lazy::new(Default::default);
3431
#[allow(clippy::expect_used)]
35-
pub fn style_no() -> ProgressStyle {
32+
pub static STYLE_NO: Lazy<ProgressStyle> = Lazy::new(|| {
3633
ProgressStyle::default_bar()
3734
.template("{spinner} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {pos:.cyan}/{len:.blue}")
3835
.expect("Progess bar template parse failure")
3936
.progress_chars("#>-")
40-
}
41-
37+
});
4238
#[allow(clippy::expect_used)]
43-
pub fn style_byte() -> ProgressStyle {
39+
pub static STYLE_BYTE: Lazy<ProgressStyle> = Lazy::new(|| {
4440
ProgressStyle::default_bar()
4541
.template(
4642
"{spinner} [{bytes_per_sec}] [{wide_bar:.cyan/blue}] {bytes:.cyan}/{total_bytes:.blue}",
4743
)
4844
.expect("Progess bar template parse failure")
4945
.progress_chars("#>-")
50-
}
46+
});
5147

5248
fn main() -> ExitCode {
5349
let cli = Ferium::parse();

src/subcommands/modpack/upgrade.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
download::{clean, download, read_overrides},
3-
style_byte, TICK,
3+
STYLE_BYTE, TICK,
44
};
55
use anyhow::Result;
66
use colored::Colorize;
@@ -32,7 +32,7 @@ pub async fn upgrade(modrinth: &Ferinth, curseforge: &Furse, modpack: &'_ Modpac
3232
match &modpack.identifier {
3333
ModpackIdentifier::CurseForgeModpack(project_id) => {
3434
println!("{}", "Downloading Modpack".bold());
35-
let progress_bar = ProgressBar::new(0).with_style(style_byte());
35+
let progress_bar = ProgressBar::new(0).with_style(STYLE_BYTE.clone());
3636
let modpack_file = download_curseforge_modpack(
3737
&curseforge.clone(),
3838
*project_id,
@@ -110,7 +110,7 @@ pub async fn upgrade(modrinth: &Ferinth, curseforge: &Furse, modpack: &'_ Modpac
110110
},
111111
ModpackIdentifier::ModrinthModpack(project_id) => {
112112
println!("{}", "Downloading Modpack".bold());
113-
let progress_bar = ProgressBar::new(0).with_style(style_byte());
113+
let progress_bar = ProgressBar::new(0).with_style(STYLE_BYTE.clone());
114114
let modpack_file = download_modrinth_modpack(
115115
&modrinth.clone(),
116116
project_id,

src/subcommands/upgrade.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
download::{clean, download},
3-
style_no, CROSS, TICK, YELLOW_TICK,
3+
CROSS, STYLE_NO, TICK, YELLOW_TICK,
44
};
55
use anyhow::{anyhow, bail, Result};
66
use colored::Colorize;
@@ -32,7 +32,7 @@ pub async fn upgrade(
3232
let profile = Arc::new(profile.clone());
3333
let to_download = Arc::new(Mutex::new(Vec::new()));
3434
let progress_bar = Arc::new(Mutex::new(
35-
ProgressBar::new(profile.mods.len() as u64).with_style(style_no()),
35+
ProgressBar::new(profile.mods.len() as u64).with_style(STYLE_NO.clone()),
3636
));
3737
let backwards_compat_msg = Arc::new(AtomicBool::new(false));
3838
let error = Arc::new(AtomicBool::new(false));

0 commit comments

Comments
 (0)