diff options
| author | Fuwn <[email protected]> | 2023-04-18 01:47:25 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-18 01:47:25 -0700 |
| commit | cfeb34870d78939133222ba61e6a1a5b82d78364 (patch) | |
| tree | 260c3f2c46283ade8083c93b0cc9e754e8c5fe97 /src/modules | |
| parent | feat(news): add a new news entry (diff) | |
| download | locus-cfeb34870d78939133222ba61e6a1a5b82d78364.tar.xz locus-cfeb34870d78939133222ba61e6a1a5b82d78364.zip | |
refactor(src): drop once_cell dependency for standard library
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/contact.rs | 6 | ||||
| -rw-r--r-- | src/modules/cryptocurrency.rs | 5 | ||||
| -rw-r--r-- | src/modules/interests.rs | 6 | ||||
| -rw-r--r-- | src/modules/remarks.rs | 5 | ||||
| -rw-r--r-- | src/modules/search.rs | 21 | ||||
| -rw-r--r-- | src/modules/skills.rs | 6 | ||||
| -rw-r--r-- | src/modules/stocks.rs | 5 | ||||
| -rw-r--r-- | src/modules/uptime.rs | 5 |
8 files changed, 30 insertions, 29 deletions
diff --git a/src/modules/contact.rs b/src/modules/contact.rs index aaeba96..68b8100 100644 --- a/src/modules/contact.rs +++ b/src/modules/contact.rs @@ -16,13 +16,11 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -use std::collections::HashMap; - -use once_cell::sync::Lazy; +use std::{collections::HashMap, sync::LazyLock}; type ContactMap = HashMap<String, HashMap<String, String>>; -static CONTACT_MAP: Lazy<ContactMap> = Lazy::new(|| { +static CONTACT_MAP: LazyLock<ContactMap> = LazyLock::new(|| { serde_json::from_str(include_str!("../../content/json/contacts.json")) .unwrap() }); diff --git a/src/modules/cryptocurrency.rs b/src/modules/cryptocurrency.rs index c0fc4b5..7f9f40c 100644 --- a/src/modules/cryptocurrency.rs +++ b/src/modules/cryptocurrency.rs @@ -16,12 +16,13 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -use once_cell::sync::Lazy; +use std::sync::LazyLock; + use serde::Deserialize; use crate::{response::success, route::track_mount}; -static REFERRALS: Lazy<Vec<Referral>> = Lazy::new(|| { +static REFERRALS: LazyLock<Vec<Referral>> = LazyLock::new(|| { serde_json::from_str(include_str!( "../../content/json/cryptocurrency_referrals.json" )) diff --git a/src/modules/interests.rs b/src/modules/interests.rs index 3a797a6..fcb8bf8 100644 --- a/src/modules/interests.rs +++ b/src/modules/interests.rs @@ -16,13 +16,11 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -use std::collections::HashMap; - -use once_cell::sync::Lazy; +use std::{collections::HashMap, sync::LazyLock}; type InterestMap = HashMap<String, HashMap<String, String>>; -static INTEREST_MAP: Lazy<InterestMap> = Lazy::new(|| { +static INTEREST_MAP: LazyLock<InterestMap> = LazyLock::new(|| { serde_json::from_str(include_str!("../../content/json/interests.json")) .unwrap() }); diff --git a/src/modules/remarks.rs b/src/modules/remarks.rs index 60c4571..03ede11 100644 --- a/src/modules/remarks.rs +++ b/src/modules/remarks.rs @@ -16,10 +16,11 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -use once_cell::sync::Lazy; +use std::sync::LazyLock; + use serde::{Deserialize, Serialize}; -static REMARKS: Lazy<Vec<Remark>> = Lazy::new(|| { +static REMARKS: LazyLock<Vec<Remark>> = LazyLock::new(|| { serde_json::from_str(include_str!("../../content/json/remarks.json")).unwrap() }); diff --git a/src/modules/search.rs b/src/modules/search.rs index 14a0f9e..12a2c80 100644 --- a/src/modules/search.rs +++ b/src/modules/search.rs @@ -16,18 +16,20 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -use std::{fmt::Write, sync::Mutex}; +use std::{ + fmt::Write, + sync::{LazyLock, Mutex}, +}; -use once_cell::sync::Lazy; use tantivy::schema; use tempfile::TempDir; const SEARCH_INDEX_SIZE: usize = 10_000_000; const SEARCH_SIZE: usize = 10; -static INDEX_PATH: Lazy<Mutex<TempDir>> = - Lazy::new(|| Mutex::new(TempDir::new().unwrap())); -static SCHEMA: Lazy<Mutex<schema::Schema>> = Lazy::new(|| { +static INDEX_PATH: LazyLock<Mutex<TempDir>> = + LazyLock::new(|| Mutex::new(TempDir::new().unwrap())); +static SCHEMA: LazyLock<Mutex<schema::Schema>> = LazyLock::new(|| { Mutex::new({ let mut schema_builder = schema::Schema::builder(); @@ -38,7 +40,7 @@ static SCHEMA: Lazy<Mutex<schema::Schema>> = Lazy::new(|| { schema_builder.build() }) }); -static INDEX: Lazy<Mutex<tantivy::Index>> = Lazy::new(|| { +static INDEX: LazyLock<Mutex<tantivy::Index>> = LazyLock::new(|| { Mutex::new({ tantivy::Index::create_in_dir( &(*INDEX_PATH.lock().unwrap()), @@ -47,9 +49,10 @@ static INDEX: Lazy<Mutex<tantivy::Index>> = Lazy::new(|| { .unwrap() }) }); -static INDEX_WRITER: Lazy<Mutex<tantivy::IndexWriter>> = Lazy::new(|| { - Mutex::new((*INDEX.lock().unwrap()).writer(SEARCH_INDEX_SIZE).unwrap()) -}); +static INDEX_WRITER: LazyLock<Mutex<tantivy::IndexWriter>> = + LazyLock::new(|| { + Mutex::new((*INDEX.lock().unwrap()).writer(SEARCH_INDEX_SIZE).unwrap()) + }); pub(super) fn module(router: &mut windmark::Router) { crate::route::track_mount( diff --git a/src/modules/skills.rs b/src/modules/skills.rs index b6c8853..bf62a4d 100644 --- a/src/modules/skills.rs +++ b/src/modules/skills.rs @@ -16,13 +16,11 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -use std::collections::HashMap; - -use once_cell::sync::Lazy; +use std::{collections::HashMap, sync::LazyLock}; type SkillTree = HashMap<String, Vec<HashMap<String, Option<Vec<String>>>>>; -static SKILL_TREE: Lazy<SkillTree> = Lazy::new(|| { +static SKILL_TREE: LazyLock<SkillTree> = LazyLock::new(|| { serde_json::from_str(include_str!("../../content/json/skills.json")).unwrap() }); diff --git a/src/modules/stocks.rs b/src/modules/stocks.rs index afa1c5d..f3519f1 100644 --- a/src/modules/stocks.rs +++ b/src/modules/stocks.rs @@ -16,12 +16,13 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -use once_cell::sync::Lazy; +use std::sync::LazyLock; + use serde::Deserialize; use crate::{response::success, route::track_mount}; -static REFERRALS: Lazy<Vec<Referral>> = Lazy::new(|| { +static REFERRALS: LazyLock<Vec<Referral>> = LazyLock::new(|| { serde_json::from_str(include_str!( "../../content/json/stock_market_referrals.json" )) diff --git a/src/modules/uptime.rs b/src/modules/uptime.rs index 67161c5..365c234 100644 --- a/src/modules/uptime.rs +++ b/src/modules/uptime.rs @@ -16,10 +16,11 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -use once_cell::sync::Lazy; +use std::sync::LazyLock; + use tokio::time::Instant; -static UPTIME: Lazy<Instant> = Lazy::new(Instant::now); +static UPTIME: LazyLock<Instant> = LazyLock::new(Instant::now); pub fn module(router: &mut windmark::Router) { UPTIME.elapsed(); |