Prechádzať zdrojové kódy

replace lazy_static uses with once_cell (#1391)

chip 4 rokov pred
rodič
commit
b79462e5cc
3 zmenil súbory, kde vykonal 6 pridanie a 11 odobranie
  1. 0 1
      tauri/Cargo.toml
  2. 4 6
      tauri/src/app/event.rs
  3. 2 4
      tauri/src/salt.rs

+ 0 - 1
tauri/Cargo.toml

@@ -21,7 +21,6 @@ features = [ "api-all" ]
 serde_json = "1.0"
 serde = { version = "1.0", features = [ "derive" ] }
 base64 = "0.13.0"
-lazy_static = "1.4.0"
 tokio = { version = "1.4", features = ["rt", "rt-multi-thread", "sync"] }
 futures = "0.3"
 async-trait = "0.1"

+ 4 - 6
tauri/src/app/event.rs

@@ -5,10 +5,10 @@ use std::{
 };
 
 use crate::ApplicationDispatcherExt;
-use lazy_static::lazy_static;
 use once_cell::sync::Lazy;
 use serde::Serialize;
 use serde_json::Value as JsonValue;
+use uuid::Uuid;
 
 /// Event identifier.
 pub type EventId = u64;
@@ -25,11 +25,9 @@ struct EventHandler {
 
 type Listeners = Arc<Mutex<HashMap<String, Vec<EventHandler>>>>;
 
-lazy_static! {
-  static ref EMIT_FUNCTION_NAME: String = uuid::Uuid::new_v4().to_string();
-  static ref EVENT_LISTENERS_OBJECT_NAME: String = uuid::Uuid::new_v4().to_string();
-  static ref EVENT_QUEUE_OBJECT_NAME: String = uuid::Uuid::new_v4().to_string();
-}
+static EMIT_FUNCTION_NAME: Lazy<String> = Lazy::new(|| Uuid::new_v4().to_string());
+static EVENT_LISTENERS_OBJECT_NAME: Lazy<String> = Lazy::new(|| Uuid::new_v4().to_string());
+static EVENT_QUEUE_OBJECT_NAME: Lazy<String> = Lazy::new(|| Uuid::new_v4().to_string());
 
 /// Gets the listeners map.
 fn listeners() -> &'static Listeners {

+ 2 - 4
tauri/src/salt.rs

@@ -1,6 +1,6 @@
 use std::sync::Mutex;
 
-use lazy_static::lazy_static;
+use once_cell::sync::Lazy;
 use uuid::Uuid;
 
 /// A salt definition.
@@ -9,9 +9,7 @@ struct Salt {
   one_time: bool,
 }
 
-lazy_static! {
-  static ref SALTS: Mutex<Vec<Salt>> = Mutex::new(vec![]);
-}
+static SALTS: Lazy<Mutex<Vec<Salt>>> = Lazy::new(Mutex::default);
 
 /// Generates a one time Salt and returns its string representation.
 pub fn generate() -> String {