aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs7
-rw-r--r--src/modules/contact.rs6
-rw-r--r--src/modules/cryptocurrency.rs5
-rw-r--r--src/modules/interests.rs6
-rw-r--r--src/modules/remarks.rs5
-rw-r--r--src/modules/search.rs21
-rw-r--r--src/modules/skills.rs6
-rw-r--r--src/modules/stocks.rs5
-rw-r--r--src/modules/uptime.rs5
-rw-r--r--src/response.rs4
-rw-r--r--src/route.rs15
11 files changed, 44 insertions, 41 deletions
diff --git a/src/main.rs b/src/main.rs
index 8d45dbd..19c0cd7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -16,7 +16,7 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-#![feature(const_extern_fn, async_closure)]
+#![feature(const_extern_fn, async_closure, lazy_cell)]
#![deny(
warnings,
nonstandard_style,
@@ -38,9 +38,8 @@ mod xml;
#[macro_use]
extern crate log;
-use std::sync::Mutex;
+use std::sync::{LazyLock, Mutex};
-use once_cell::sync::Lazy;
use pickledb::PickleDb;
use tokio::time::Instant;
@@ -49,7 +48,7 @@ const ERROR_HANDLER_RESPONSE: &str =
refreshing the page, if that doesn't change anything; contact Fuwn! \
-static DATABASE: Lazy<Mutex<PickleDb>> = Lazy::new(|| {
+static DATABASE: LazyLock<Mutex<PickleDb>> = LazyLock::new(|| {
Mutex::new({
if std::fs::File::open(".locus/locus.db").is_ok() {
PickleDb::load_json(
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();
diff --git a/src/response.rs b/src/response.rs
index 5661938..a8f8848 100644
--- a/src/response.rs
+++ b/src/response.rs
@@ -15,9 +15,9 @@
// Copyright (C) 2022-2023 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use once_cell::sync::Lazy;
+use std::sync::LazyLock;
-static QUOTES: Lazy<Vec<String>> = Lazy::new(|| {
+static QUOTES: LazyLock<Vec<String>> = LazyLock::new(|| {
serde_json::from_str(include_str!("../content/json/quotes.json")).unwrap()
});
diff --git a/src/route.rs b/src/route.rs
index d1f1f41..e32cd98 100644
--- a/src/route.rs
+++ b/src/route.rs
@@ -16,9 +16,12 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::{collections::HashMap, future::IntoFuture, sync::Mutex};
+use std::{
+ collections::HashMap,
+ future::IntoFuture,
+ sync::{LazyLock, Mutex},
+};
-use once_cell::sync::Lazy;
use tokio::time::Instant;
use windmark::context::RouteContext;
@@ -27,8 +30,8 @@ pub const CACHE_RATE: u64 = 1;
#[cfg(not(debug_assertions))]
pub const CACHE_RATE: u64 = 60 * 5;
-pub static ROUTES: Lazy<Mutex<HashMap<String, Route>>> =
- Lazy::new(|| Mutex::new(HashMap::new()));
+pub static ROUTES: LazyLock<Mutex<HashMap<String, Route>>> =
+ LazyLock::new(|| Mutex::new(HashMap::new()));
#[derive(Debug)]
pub struct Route {
@@ -67,8 +70,8 @@ pub fn track_mount<F, R>(
}
pub fn cache(context: &RouteContext, response: &str) {
- static LAST_CACHED: Lazy<Mutex<Instant>> =
- Lazy::new(|| Mutex::new(Instant::now()));
+ static LAST_CACHED: LazyLock<Mutex<Instant>> =
+ LazyLock::new(|| Mutex::new(Instant::now()));
if (*LAST_CACHED.lock().unwrap()).elapsed()
>= std::time::Duration::from_secs(CACHE_RATE)