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:
yaroslav k 2026-08-15 14:56:54 +03:00
parent 6b792734b6
commit 444f046990
4 changed files with 3421 additions and 35 deletions

4
.gitignore vendored
View File

@ -3,9 +3,7 @@
debug/ debug/
target/ target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # Cargo.lock is tracked: the app is a binary, builds should be reproducible
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt # These are backup files generated by rustfmt
**/*.rs.bk **/*.rs.bk

3393
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,6 @@ thiserror = "2.0.16"
itertools = "0.14.0" itertools = "0.14.0"
dotenvy = "0.15.7" dotenvy = "0.15.7"
pretty_env_logger = "0.5.0" pretty_env_logger = "0.5.0"
lazy_static = "1.5.0"
leptos-use = "0.16.2" leptos-use = "0.16.2"
log = "0.4.28" log = "0.4.28"
nucleo-matcher = "0.3.1" nucleo-matcher = "0.3.1"
@ -72,9 +71,9 @@ style-file = "style/main.scss"
# Optional. Env: LEPTOS_ASSETS_DIR. # Optional. Env: LEPTOS_ASSETS_DIR.
assets-dir = "assets" 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. # 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 # 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. # [Optional] Command to use when running end2end tests. It will run in the end2end dir.
# [Windows] for non-WSL use "npx.cmd playwright test" # [Windows] for non-WSL use "npx.cmd playwright test"
# This binary name can be checked in Powershell with Get-Command npx # This binary name can be checked in Powershell with Get-Command npx

View File

@ -1,35 +1,31 @@
//! Bundled static game data. //! Bundled static game data.
//! //!
//! `ITEMS_REFS` loads the 5e.tools-format JSON files (`data/*.json`, //! `ITEMS_REFS` loads the 5e.tools-format JSON files (`data/*.json`, roughly
//! roughly 5k items) once at first use via `lazy_static` and indexes them //! 5k items) once at first use via `std::sync::LazyLock` and indexes them by
//! by name. `ITEMS_NAMES` is the flat name list used for fuzzy search. //! name. `ITEMS_NAMES` is the flat name list used for fuzzy search.
use std::sync::LazyLock;
use crate::prelude::*; use crate::prelude::*;
use lazy_static::lazy_static;
lazy_static! {
/// All known items, indexed by name, from the bundled 5e.tools JSON files. /// 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 /// Built once at first access: entries with the same name are merged (a
/// weight fills in, `rest` fields concatenate). Note `foundry.json` is /// missing weight fills in, `rest` fields concatenate).
/// currently loaded twice — see `utils::read_items`. pub static ITEMS_REFS: LazyLock<ItemReferenceMap> = LazyLock::new(|| {
pub static ref ITEMS_REFS: ItemReferenceMap = {
let mut map = HashMap::with_capacity(5_000); let mut map = HashMap::with_capacity(5_000);
utils::read_items(include_str!("../../data/items.json"), &mut map); 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/base.json"), &mut map);
utils::read_items(include_str!("../../data/foundry.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/magic.json"), &mut map);
utils::read_items(include_str!("../../data/foundry.json"), &mut map);
info!("Loaded {} items", map.len()); 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 /// Flat list of item names; the feed for the fuzzy matcher
/// (`ItemSearchField`). /// (`ItemSearchField`).
pub static ref ITEMS_NAMES: Vec<&'static String> = { pub static ITEMS_NAMES: LazyLock<Vec<&'static str>> =
ITEMS_REFS.0.keys().collect() LazyLock::new(|| ITEMS_REFS.0.keys().map(String::as_str).collect());
};
}