src/global/structs/library.rs

28 lines · 546 bytes

6 symbols in this file
 1use crate::global::traits::Collection;
 2
 3use super::Item;
 4use serde::{Deserialize, Serialize};
 5use typemap::Key;
 6
 7#[derive(Clone, Default, Serialize, Deserialize)]
 8pub struct Library(pub Vec<Item>);
 9
10impl Key for Library {
11    type Value = Self;
12}
13
14impl Collection<Item> for Library {
15    const INDEX_PATH: &'static str = "library.json";
16
17    fn items(&self) -> &Vec<Item> {
18        &self.0
19    }
20
21    fn items_mut(&mut self) -> &mut Vec<Item> {
22        &mut self.0
23    }
24
25    fn from_items(items: Vec<Item>) -> Self {
26        Self(items)
27    }
28}