From e75474fde7157a5fc86d42e9c41d1385212bf818 Mon Sep 17 00:00:00 2001 From: Brian Bowman Date: Sat, 9 Jul 2022 05:53:13 -0500 Subject: [PATCH] Replace `lazy_static` with `once_cell` `once_cell` is a simpler macroless alternative that will be added to the standard library. --- src-tauri/Cargo.lock | 6 +++--- src-tauri/Cargo.toml | 2 +- src-tauri/src/downloader.rs | 9 ++------- src-tauri/src/main.rs | 9 ++------- src-tauri/src/proxy.rs | 9 ++------- 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 5e2a403..877c0eb 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -723,7 +723,7 @@ dependencies = [ "http", "hudsucker", "is_elevated", - "lazy_static", + "once_cell", "open", "rcgen", "registry", @@ -2354,9 +2354,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.10.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" +checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" [[package]] name = "opaque-debug" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 52681a7..fff4a4b 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -33,7 +33,7 @@ zip-extract = "0.1.1" zip = "0.6.2" # For creating a "global" downloads list. -lazy_static = "1.4.0" +once_cell = "1.13.0" # Program opener. open = "2.1.2" diff --git a/src-tauri/src/downloader.rs b/src-tauri/src/downloader.rs index be6708a..4b779af 100644 --- a/src-tauri/src/downloader.rs +++ b/src-tauri/src/downloader.rs @@ -1,4 +1,4 @@ -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::sync::Mutex; use std::cmp::min; @@ -8,12 +8,7 @@ use std::io::Write; use futures_util::StreamExt; // This will create a downloads list that will be used to check if we should continue downloading the file -lazy_static! { - static ref DOWNLOADS: Mutex> = { - let m = Vec::new(); - Mutex::new(m) - }; -} +static DOWNLOADS: Lazy>> = Lazy::new(|| Mutex::new(Vec::new())); // Lots of help from: https://gist.github.com/giuliano-oliveira/4d11d6b3bb003dba3a1b53f43d81b30d // and docs ofc diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index b65ad7a..e9e72da 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -3,7 +3,7 @@ all(not(debug_assertions), target_os = "windows"), windows_subsystem = "windows" )] -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::{sync::Mutex, collections::HashMap}; use std::path::PathBuf; @@ -20,12 +20,7 @@ mod lang; mod proxy; mod web; -lazy_static! { - static ref WATCH_GAME_PROCESS: Mutex = { - let m = "".to_string(); - Mutex::new(m) - }; -} +static WATCH_GAME_PROCESS: Lazy> = Lazy::new(|| Mutex::new(String::new())); fn main() { // Start the game process watcher. diff --git a/src-tauri/src/proxy.rs b/src-tauri/src/proxy.rs index 35661b9..415bc43 100644 --- a/src-tauri/src/proxy.rs +++ b/src-tauri/src/proxy.rs @@ -3,7 +3,7 @@ * https://github.com/omjadas/hudsucker/blob/main/examples/log.rs */ -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use std::{sync::Mutex, str::FromStr}; use rcgen::*; @@ -30,12 +30,7 @@ async fn shutdown_signal() { } // Global ver for getting server address. -lazy_static! { - static ref SERVER: Mutex = { - let m = "http://localhost:443".to_string(); - Mutex::new(m) - }; -} +static SERVER: Lazy> = Lazy::new(|| Mutex::new("http://localhost:443".to_string())); #[derive(Clone)] struct ProxyHandler;