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 committed 2026-08-15 14:56:54 +03:00
1 parent 6b792734b6
commit 444f046990
4 files changed
+3421 -35

No files matched your search

+19 -23
View File
@@ -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 = {
let mut map = HashMap::with_capacity(5_000);
/// 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);
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);
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
/// (`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());