From a25e49f4dfa17688c159aa72ae9c4733517aeee8 Mon Sep 17 00:00:00 2001 From: AmrDeveloper Date: Tue, 4 Jun 2024 21:43:50 +0200 Subject: [PATCH] feat: Remove lazy_static crate --- Cargo.lock | 7 ------- Cargo.toml | 1 - src/main.rs | 13 +++++++------ src/schema.rs | 16 +++++++++------- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7964ab..0380cc5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,7 +109,6 @@ dependencies = [ "gitql-engine", "gitql-parser", "gitql-std", - "lazy_static", ] [[package]] @@ -311,12 +310,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.153" diff --git a/Cargo.toml b/Cargo.toml index c46a19d..5346b68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,5 @@ gitql-cli = "0.20.0" gitql-ast = "0.18.0" gitql-parser = "0.19.0" gitql-engine = "0.20.0" -lazy_static = "1.4.0" atty = "0.2.14" clang-sys = "1.7.0" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index bea2f0a..e393655 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,8 +20,8 @@ use gitql_std::aggregation::aggregation_function_signatures; use gitql_std::aggregation::aggregation_functions; use gitql_std::function::standard_function_signatures; use gitql_std::function::standard_functions; -use schema::TABLES_FIELDS_NAMES; -use schema::TABLES_FIELDS_TYPES; +use schema::tables_fields_names; +use schema::tables_fields_types; mod arguments; mod data_provider; @@ -45,9 +45,10 @@ fn main() { reporter.report_diagnostic("", Diagnostic::error(error.as_str())); return; } + let schema = Schema { - tables_fields_names: TABLES_FIELDS_NAMES.to_owned(), - tables_fields_types: TABLES_FIELDS_TYPES.to_owned(), + tables_fields_names: tables_fields_names().to_owned(), + tables_fields_types: tables_fields_types().to_owned(), }; let std_signatures = standard_function_signatures(); @@ -83,8 +84,8 @@ fn launch_clangql_repl(arguments: Arguments) { } let schema = Schema { - tables_fields_names: TABLES_FIELDS_NAMES.to_owned(), - tables_fields_types: TABLES_FIELDS_TYPES.to_owned(), + tables_fields_names: tables_fields_names().to_owned(), + tables_fields_types: tables_fields_types().to_owned(), }; let std_signatures = standard_function_signatures(); diff --git a/src/schema.rs b/src/schema.rs index a38b735..bf07d90 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,9 +1,10 @@ use gitql_core::types::DataType; -use lazy_static::lazy_static; use std::collections::HashMap; +use std::sync::OnceLock; -lazy_static! { - pub static ref TABLES_FIELDS_TYPES: HashMap<&'static str, DataType> = { +pub fn tables_fields_types() -> &'static HashMap<&'static str, DataType> { + static HASHMAP: OnceLock> = OnceLock::new(); + HASHMAP.get_or_init(|| { let mut map = HashMap::new(); map.insert("name", DataType::Text); map.insert("type", DataType::Text); @@ -40,11 +41,12 @@ lazy_static! { map.insert("column", DataType::Integer); map.insert("offset", DataType::Integer); map - }; + }) } -lazy_static! { - pub static ref TABLES_FIELDS_NAMES: HashMap<&'static str, Vec<&'static str>> = { +pub fn tables_fields_names() -> &'static HashMap<&'static str, Vec<&'static str>> { + static HASHMAP: OnceLock>> = OnceLock::new(); + HASHMAP.get_or_init(|| { let mut map = HashMap::new(); map.insert( "classes", @@ -107,5 +109,5 @@ lazy_static! { ], ); map - }; + }) }