replace lazy_static with std::sync::LazyLock; commit Cargo.lock
lazy_static removed from Cargo.toml (the only dependency removal for now, per decision). ITEMS_REFS/ITEMS_NAMES are now LazyLock statics; the duplicate foundry.json load is dropped and the no-op HashMap roundtrip is gone. Cargo.lock is now tracked: the app is a binary and builds should be reproducible.
This commit is contained in:
parent
6b792734b6
commit
444f046990
4
.gitignore
vendored
4
.gitignore
vendored
@ -3,9 +3,7 @@
|
||||
debug/
|
||||
target/
|
||||
|
||||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||
Cargo.lock
|
||||
# Cargo.lock is tracked: the app is a binary, builds should be reproducible
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
**/*.rs.bk
|
||||
|
||||
3393
Cargo.lock
generated
Normal file
3393
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -21,7 +21,6 @@ thiserror = "2.0.16"
|
||||
itertools = "0.14.0"
|
||||
dotenvy = "0.15.7"
|
||||
pretty_env_logger = "0.5.0"
|
||||
lazy_static = "1.5.0"
|
||||
leptos-use = "0.16.2"
|
||||
log = "0.4.28"
|
||||
nucleo-matcher = "0.3.1"
|
||||
@ -72,9 +71,9 @@ style-file = "style/main.scss"
|
||||
# Optional. Env: LEPTOS_ASSETS_DIR.
|
||||
assets-dir = "assets"
|
||||
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
|
||||
site-addr = "127.0.0.1:3000"
|
||||
site-addr = "127.0.0.1:3110"
|
||||
# The port to use for automatic reload monitoring
|
||||
reload-port = 3001
|
||||
reload-port = 3111
|
||||
# [Optional] Command to use when running end2end tests. It will run in the end2end dir.
|
||||
# [Windows] for non-WSL use "npx.cmd playwright test"
|
||||
# This binary name can be checked in Powershell with Get-Command npx
|
||||
|
||||
@ -1,35 +1,31 @@
|
||||
//! Bundled static game data.
|
||||
//!
|
||||
//! `ITEMS_REFS` loads the 5e.tools-format JSON files (`data/*.json`,
|
||||
//! roughly 5k items) once at first use via `lazy_static` and indexes them
|
||||
//! by name. `ITEMS_NAMES` is the flat name list used for fuzzy search.
|
||||
//! `ITEMS_REFS` loads the 5e.tools-format JSON files (`data/*.json`, roughly
|
||||
//! 5k items) once at first use via `std::sync::LazyLock` and indexes them by
|
||||
//! name. `ITEMS_NAMES` is the flat name list used for fuzzy search.
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use crate::prelude::*;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
|
||||
lazy_static! {
|
||||
/// All known items, indexed by name, from the bundled 5e.tools JSON files.
|
||||
///
|
||||
/// Built once at startup: entries with the same name are merged (a missing
|
||||
/// weight fills in, `rest` fields concatenate). Note `foundry.json` is
|
||||
/// currently loaded twice — see `utils::read_items`.
|
||||
pub static ref ITEMS_REFS: ItemReferenceMap = {
|
||||
/// Built once at first access: entries with the same name are merged (a
|
||||
/// missing weight fills in, `rest` fields concatenate).
|
||||
pub static ITEMS_REFS: LazyLock<ItemReferenceMap> = LazyLock::new(|| {
|
||||
let mut map = HashMap::with_capacity(5_000);
|
||||
|
||||
utils::read_items(include_str!("../../data/items.json"), &mut map);
|
||||
utils::read_items(include_str!("../../data/base.json"), &mut map);
|
||||
utils::read_items(include_str!("../../data/foundry.json"), &mut map);
|
||||
utils::read_items(include_str!("../../data/magic.json"), &mut map);
|
||||
utils::read_items(include_str!("../../data/foundry.json"), &mut map);
|
||||
|
||||
info!("Loaded {} items", map.len());
|
||||
|
||||
ItemReferenceMap(HashMap::from_iter(map.into_iter()))
|
||||
};
|
||||
ItemReferenceMap(map)
|
||||
});
|
||||
|
||||
/// Flat list of item names; the feed for the fuzzy matcher
|
||||
/// (`ItemSearchField`).
|
||||
pub static ref ITEMS_NAMES: Vec<&'static String> = {
|
||||
ITEMS_REFS.0.keys().collect()
|
||||
};
|
||||
}
|
||||
pub static ITEMS_NAMES: LazyLock<Vec<&'static str>> =
|
||||
LazyLock::new(|| ITEMS_REFS.0.keys().map(String::as_str).collect());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user