aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-08-27 22:29:06 -0700
committerFuwn <[email protected]>2022-08-27 22:29:06 -0700
commit83fc1aab2e15f60b6e7b85e7831d6591b4d1ab36 (patch)
tree43ddb3f37117e61b1caa619b72c96eafa21cf63b /src
parentfix(main.rs): enable feature for actions (diff)
downloadlocus-83fc1aab2e15f60b6e7b85e7831d6591b4d1ab36.tar.xz
locus-83fc1aab2e15f60b6e7b85e7831d6591b4d1ab36.zip
feat: bump toolchain to nightly-2022-08-23
Diffstat (limited to 'src')
-rw-r--r--src/macros.rs6
-rw-r--r--src/main.rs7
-rw-r--r--src/modules/contact.rs6
-rw-r--r--src/modules/interests.rs6
-rw-r--r--src/modules/random.rs2
-rw-r--r--src/modules/remarks.rs5
-rw-r--r--src/modules/search.rs22
-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/route.rs11
11 files changed, 43 insertions, 38 deletions
diff --git a/src/macros.rs b/src/macros.rs
index 724ef5e..7a39dbd 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -16,9 +16,9 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::lazy::SyncLazy;
+use once_cell::sync::Lazy;
-pub static QUOTES: SyncLazy<Vec<String>> = SyncLazy::new(|| {
+pub static QUOTES: Lazy<Vec<String>> = Lazy::new(|| {
serde_json::from_str(include_str!("../content/json/quotes.json")).unwrap()
});
@@ -42,7 +42,7 @@ macro_rules! success {
body: &$body,
hits: &$crate::route::hits_from($context.url.path()),
quote: {
- use rand::seq::SliceRandom;
+ use rand::prelude::SliceRandom;
&$crate::macros::QUOTES
.choose(&mut rand::thread_rng())
diff --git a/src/main.rs b/src/main.rs
index 4ba8f83..38109cf 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(array_from_fn, const_extern_fn, is_some_with, once_cell)]
+#![feature(const_extern_fn, is_some_with, once_cell)]
#![deny(
warnings,
nonstandard_style,
@@ -37,8 +37,9 @@ mod xml;
#[macro_use]
extern crate log;
-use std::{lazy::SyncLazy, sync::Mutex};
+use std::sync::Mutex;
+use once_cell::sync::Lazy;
use pickledb::PickleDb;
use tokio::time::Instant;
@@ -47,7 +48,7 @@ const ERROR_HANDLER_RESPONSE: &str =
refreshing the page, if that doesn't change anything; contact Fuwn! \
-static DATABASE: SyncLazy<Mutex<PickleDb>> = SyncLazy::new(|| {
+static DATABASE: Lazy<Mutex<PickleDb>> = Lazy::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 9999aa9..c9ce993 100644
--- a/src/modules/contact.rs
+++ b/src/modules/contact.rs
@@ -16,11 +16,13 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::{collections::HashMap, lazy::SyncLazy};
+use std::collections::HashMap;
+
+use once_cell::sync::Lazy;
type ContactMap = HashMap<String, HashMap<String, String>>;
-static CONTACT_MAP: SyncLazy<ContactMap> = SyncLazy::new(|| {
+static CONTACT_MAP: Lazy<ContactMap> = Lazy::new(|| {
serde_json::from_str(include_str!("../../content/json/contacts.json"))
.unwrap()
});
diff --git a/src/modules/interests.rs b/src/modules/interests.rs
index 2cd8328..4db805f 100644
--- a/src/modules/interests.rs
+++ b/src/modules/interests.rs
@@ -16,11 +16,13 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::{collections::HashMap, lazy::SyncLazy};
+use std::collections::HashMap;
+
+use once_cell::sync::Lazy;
type InterestMap = HashMap<String, HashMap<String, String>>;
-static INTEREST_MAP: SyncLazy<InterestMap> = SyncLazy::new(|| {
+static INTEREST_MAP: Lazy<InterestMap> = Lazy::new(|| {
serde_json::from_str(include_str!("../../content/json/interests.json"))
.unwrap()
});
diff --git a/src/modules/random.rs b/src/modules/random.rs
index 799376a..9320ac6 100644
--- a/src/modules/random.rs
+++ b/src/modules/random.rs
@@ -16,7 +16,7 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use rand::seq::SliceRandom;
+use rand::prelude::SliceRandom;
pub fn module(router: &mut windmark::Router) {
crate::route::track_mount(
diff --git a/src/modules/remarks.rs b/src/modules/remarks.rs
index 780b72a..8cd9d6c 100644
--- a/src/modules/remarks.rs
+++ b/src/modules/remarks.rs
@@ -16,11 +16,10 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::lazy::SyncLazy;
-
+use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
-static REMARKS: SyncLazy<Vec<Remark>> = SyncLazy::new(|| {
+static REMARKS: Lazy<Vec<Remark>> = Lazy::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 2179215..6ad3898 100644
--- a/src/modules/search.rs
+++ b/src/modules/search.rs
@@ -16,17 +16,18 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::{fmt::Write, lazy::SyncLazy, sync::Mutex};
+use std::{fmt::Write, sync::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: SyncLazy<Mutex<TempDir>> =
- SyncLazy::new(|| Mutex::new(TempDir::new().unwrap()));
-static SCHEMA: SyncLazy<Mutex<schema::Schema>> = SyncLazy::new(|| {
+static INDEX_PATH: Lazy<Mutex<TempDir>> =
+ Lazy::new(|| Mutex::new(TempDir::new().unwrap()));
+static SCHEMA: Lazy<Mutex<schema::Schema>> = Lazy::new(|| {
Mutex::new({
let mut schema_builder = schema::Schema::builder();
@@ -37,7 +38,7 @@ static SCHEMA: SyncLazy<Mutex<schema::Schema>> = SyncLazy::new(|| {
schema_builder.build()
})
});
-static INDEX: SyncLazy<Mutex<tantivy::Index>> = SyncLazy::new(|| {
+static INDEX: Lazy<Mutex<tantivy::Index>> = Lazy::new(|| {
Mutex::new({
tantivy::Index::create_in_dir(
&(*INDEX_PATH.lock().unwrap()),
@@ -46,10 +47,9 @@ static INDEX: SyncLazy<Mutex<tantivy::Index>> = SyncLazy::new(|| {
.unwrap()
})
});
-static INDEX_WRITER: SyncLazy<Mutex<tantivy::IndexWriter>> =
- SyncLazy::new(|| {
- Mutex::new((*INDEX.lock().unwrap()).writer(SEARCH_INDEX_SIZE).unwrap())
- });
+static INDEX_WRITER: Lazy<Mutex<tantivy::IndexWriter>> = Lazy::new(|| {
+ Mutex::new((*INDEX.lock().unwrap()).writer(SEARCH_INDEX_SIZE).unwrap())
+});
pub(super) fn module(router: &mut windmark::Router) {
crate::route::track_mount(
@@ -85,10 +85,10 @@ pub(super) fn module(router: &mut windmark::Router) {
let top_docs = searcher
.search(
&tantivy::query::QueryParser::for_index(
- &(*INDEX.lock().unwrap()),
+ &INDEX.lock().unwrap(),
vec![path, description, content],
)
- .parse_query(&query.0.to_string())
+ .parse_query(&query.0)
.unwrap(),
&tantivy::collector::TopDocs::with_limit(SEARCH_SIZE),
)
diff --git a/src/modules/skills.rs b/src/modules/skills.rs
index bd05ceb..ec2337d 100644
--- a/src/modules/skills.rs
+++ b/src/modules/skills.rs
@@ -16,11 +16,13 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::{collections::HashMap, lazy::SyncLazy};
+use std::collections::HashMap;
+
+use once_cell::sync::Lazy;
type SkillTree = HashMap<String, Vec<HashMap<String, Option<Vec<String>>>>>;
-static SKILL_TREE: SyncLazy<SkillTree> = SyncLazy::new(|| {
+static SKILL_TREE: Lazy<SkillTree> = Lazy::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 e066dce..0d6950c 100644
--- a/src/modules/stocks.rs
+++ b/src/modules/stocks.rs
@@ -16,13 +16,12 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::lazy::SyncLazy;
-
+use once_cell::sync::Lazy;
use serde::Deserialize;
use crate::{route::track_mount, success};
-static REFERRALS: SyncLazy<Vec<Referral>> = SyncLazy::new(|| {
+static REFERRALS: Lazy<Vec<Referral>> = Lazy::new(|| {
serde_json::from_str(include_str!("../../content/json/stock_referrals.json"))
.unwrap()
});
diff --git a/src/modules/uptime.rs b/src/modules/uptime.rs
index c0b09cb..774fb37 100644
--- a/src/modules/uptime.rs
+++ b/src/modules/uptime.rs
@@ -16,11 +16,10 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::lazy::SyncLazy;
-
+use once_cell::sync::Lazy;
use tokio::time::Instant;
-static UPTIME: SyncLazy<Instant> = SyncLazy::new(Instant::now);
+static UPTIME: Lazy<Instant> = Lazy::new(Instant::now);
pub fn module(router: &mut windmark::Router) {
UPTIME.elapsed();
diff --git a/src/route.rs b/src/route.rs
index 032381d..5c43871 100644
--- a/src/route.rs
+++ b/src/route.rs
@@ -16,8 +16,9 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::{collections::HashMap, lazy::SyncLazy, sync::Mutex};
+use std::{collections::HashMap, sync::Mutex};
+use once_cell::sync::Lazy;
use tokio::time::Instant;
#[cfg(debug_assertions)]
@@ -25,8 +26,8 @@ pub const CACHE_RATE: u64 = 1;
#[cfg(not(debug_assertions))]
pub const CACHE_RATE: u64 = 60 * 5;
-pub static ROUTES: SyncLazy<Mutex<HashMap<String, Route>>> =
- SyncLazy::new(|| Mutex::new(HashMap::new()));
+pub static ROUTES: Lazy<Mutex<HashMap<String, Route>>> =
+ Lazy::new(|| Mutex::new(HashMap::new()));
#[derive(Debug)]
pub struct Route {
@@ -63,8 +64,8 @@ pub fn track_mount(
}
pub fn cache(context: &windmark::returnable::RouteContext<'_>, response: &str) {
- static LAST_CACHED: SyncLazy<Mutex<Instant>> =
- SyncLazy::new(|| Mutex::new(Instant::now()));
+ static LAST_CACHED: Lazy<Mutex<Instant>> =
+ Lazy::new(|| Mutex::new(Instant::now()));
if (*LAST_CACHED.lock().unwrap()).elapsed()
>= std::time::Duration::from_secs(CACHE_RATE)