use crate::static_data::DataLibrary; use crate::static_data::MoveData; use crate::StringKey; use hashbrown::HashMap; #[derive(Debug)] pub struct MoveLibrary { map: HashMap, list: Vec, } impl MoveLibrary { pub fn new(capacity: usize) -> MoveLibrary { MoveLibrary { map: HashMap::with_capacity(capacity), list: Vec::with_capacity(capacity), } } } impl DataLibrary<'_, MoveData> for MoveLibrary { fn map(&self) -> &HashMap { &self.map } fn list_values(&self) -> &Vec { &self.list } fn get_modify(&mut self) -> (&mut HashMap, &mut Vec) { (&mut self.map, &mut self.list) } } #[cfg(test)] pub mod tests { use crate::static_data::libraries::data_library::DataLibrary; use crate::static_data::libraries::move_library::MoveLibrary; use crate::static_data::moves::move_data::{MoveCategory, MoveData, MoveTarget}; use crate::static_data::moves::secondary_effect::SecondaryEffect; use crate::StringKey; use hashbrown::HashSet; fn build_move() -> MoveData { MoveData::new( &"foo".into(), 0, MoveCategory::Physical, 100, 100, 30, MoveTarget::Any, 0, SecondaryEffect::empty(), 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 } }