diff --git a/src/load/corebundle.rs b/src/load/corebundle.rs index b15788a..aaf2714 100644 --- a/src/load/corebundle.rs +++ b/src/load/corebundle.rs @@ -62,3 +62,39 @@ pub fn rarityvec_to_rarityhashmap(v: Vec) -> HashMap) -> HashMap { + let mut hm = HashMap::::new(); + for set in v { + hm.insert(set.set, set); + } + hm +} + + +/// A [CoreGlobals] struct where items are [HashMap]s mapping identifiers to the data they belong to. +pub struct MappedGlobals { + pub vocab_terms: HashMap, + pub keywords: HashMap, + pub regions: HashMap, + pub spell_speeds: HashMap, + pub rarities: HashMap, + pub sets: HashMap, +} + + +/// Trait allowing easy conversion from [CoreGlobals] to [MappedGlobals]. +impl From for MappedGlobals { + fn from(cg: CoreGlobals) -> Self { + MappedGlobals { + vocab_terms: vocabtermvec_to_vocabtermhashmap(cg.vocab_terms), + keywords: keywordvec_to_keywordhashmap(cg.keywords), + regions: regionvec_to_regionhashmap(cg.regions), + spell_speeds: spellspeedvec_to_spellspeedhashmap(cg.spell_speeds), + rarities: rarityvec_to_rarityhashmap(cg.rarities), + sets: setvec_to_sethashmap(cg.sets), + } + } +}