poke_data/collections/
egg_groups.rs

1use crate::data::link_context::LinkContext;
2use crate::data_structures::entity_collection::{EntityCollection, HasNameSearchIndex};
3use crate::data_structures::string_search_index::StringSearchIndex;
4use crate::models::egg_group::{EggGroup, EggGroupId};
5use crate::traits::has_identifier::IdentifierDictionary;
6use crate::traits::has_localized_names::LocalizedNamesDictionary;
7use std::collections::HashMap;
8use std::sync::Arc;
9
10pub struct EggGroupsCollection {
11    entities: HashMap<EggGroupId, Arc<EggGroup>>,
12    name_search_index: StringSearchIndex<EggGroupId>,
13}
14
15impl EntityCollection<EggGroupId, EggGroup> for EggGroupsCollection {
16    fn new(context: &LinkContext) -> Self {
17        let entities = context.egg_groups.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<EggGroupId, Arc<EggGroup>> {
29        &self.entities
30    }
31}
32
33impl HasNameSearchIndex<EggGroupId, EggGroup> for EggGroupsCollection {
34    fn name_search_index(&self) -> &StringSearchIndex<EggGroupId> {
35        &self.name_search_index
36    }
37}