poke_data/collections/
moves.rs1use crate::data::link_context::LinkContext;
2use crate::data_structures::entity_collection::{EntityCollection, HasNameSearchIndex};
3use crate::data_structures::string_search_index::StringSearchIndex;
4use crate::models::pokemon_move::{PokemonMove, PokemonMoveId};
5use crate::traits::has_identifier::IdentifierDictionary;
6use crate::traits::has_localized_names::LocalizedNamesDictionary;
7use std::collections::HashMap;
8use std::sync::Arc;
9
10pub struct MovesCollection {
11 entities: HashMap<PokemonMoveId, Arc<PokemonMove>>,
12 name_search_index: StringSearchIndex<PokemonMoveId>,
13}
14
15impl EntityCollection<PokemonMoveId, PokemonMove> for MovesCollection {
16 fn new(context: &LinkContext) -> Self {
17 let entities = context.moves.clone();
18 let mut dictionary = HashMap::new();
19 dictionary.extend(entities.build_identifier_dictionary());
20 dictionary.extend(entities.build_localized_name_dictionary());
21 let name_search_index = StringSearchIndex::new(dictionary);
22 Self {
23 entities,
24 name_search_index,
25 }
26 }
27
28 fn entities(&self) -> &HashMap<PokemonMoveId, Arc<PokemonMove>> {
29 &self.entities
30 }
31}
32
33impl HasNameSearchIndex<PokemonMoveId, PokemonMove> for MovesCollection {
34 fn name_search_index(&self) -> &StringSearchIndex<PokemonMoveId> {
35 &self.name_search_index
36 }
37}