use indexmap::IndexMap; use crate::static_data::DataLibrary; use crate::static_data::MoveData; use crate::StringKey; /// A library to store all data for moves. #[derive(Debug)] pub struct MoveLibrary { /// The underlying map. map: IndexMap, } impl MoveLibrary { /// Instantiates a new Move Library. pub fn new(capacity: usize) -> MoveLibrary { MoveLibrary { map: IndexMap::with_capacity(capacity), } } } impl DataLibrary<'_, MoveData> for MoveLibrary { fn map(&self) -> &IndexMap { &self.map } fn get_modify(&mut self) -> &mut IndexMap { &mut self.map } } #[cfg(test)] pub mod tests { use hashbrown::HashSet; use crate::static_data::libraries::data_library::DataLibrary; use crate::static_data::libraries::move_library::MoveLibrary; use crate::static_data::{MoveCategory, MoveData, MoveTarget}; use crate::StringKey; fn build_move() -> MoveData { MoveData::new( &"foo".into(), 0.into(), MoveCategory::Physical, 100, 100, 30, MoveTarget::Any, 0, None, HashSet::new(), ) } pub fn build() -> MoveLibrary { let mut lib = MoveLibrary::new(1); let m = build_move(); // Borrow as mut so we can insert let w = &mut lib; w.add(&StringKey::new("foo"), m); // Drops borrow as mut lib } }