This commit is contained in:
@@ -1,35 +1,32 @@
|
||||
use hashbrown::HashMap;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
use crate::static_data::DataLibrary;
|
||||
use crate::static_data::Item;
|
||||
use crate::StringKey;
|
||||
|
||||
/// A library to store all items.
|
||||
#[derive(Debug)]
|
||||
pub struct ItemLibrary {
|
||||
map: HashMap<StringKey, Box<Item>>,
|
||||
list: Vec<StringKey>,
|
||||
/// The underlying data structure.
|
||||
map: IndexMap<StringKey, Box<Item>>,
|
||||
}
|
||||
|
||||
impl ItemLibrary {
|
||||
/// Instantiates a new Item Library.
|
||||
pub fn new(capacity: usize) -> ItemLibrary {
|
||||
ItemLibrary {
|
||||
map: HashMap::with_capacity(capacity),
|
||||
list: Vec::with_capacity(capacity),
|
||||
map: IndexMap::with_capacity(capacity),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DataLibrary<'_, Box<Item>> for ItemLibrary {
|
||||
fn map(&self) -> &HashMap<StringKey, Box<Item>> {
|
||||
fn map(&self) -> &IndexMap<StringKey, Box<Item>> {
|
||||
&self.map
|
||||
}
|
||||
|
||||
fn list_values(&self) -> &Vec<StringKey> {
|
||||
&self.list
|
||||
}
|
||||
|
||||
fn get_modify(&mut self) -> (&mut HashMap<StringKey, Box<Item>>, &mut Vec<StringKey>) {
|
||||
(&mut self.map, &mut self.list)
|
||||
fn get_modify(&mut self) -> &mut IndexMap<StringKey, Box<Item>> {
|
||||
&mut self.map
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user