1use std::collections::HashMap;
2
3use crate::Handle;
4
5pub struct Assets<T> {
7 data: HashMap<u64, T>,
8}
9
10impl<T> Assets<T> {
11 pub fn new() -> Self {
12 Self {
13 data: HashMap::new(),
14 }
15 }
16
17 pub fn insert(&mut self, handle: Handle<T>, asset: T) {
18 self.data.insert(handle.id(), asset);
19 }
20
21 pub fn get(&self, handle: &Handle<T>) -> Option<&T> {
22 self.data.get(&handle.id())
23 }
24
25 pub fn get_mut(&mut self, handle: &Handle<T>) -> Option<&mut T> {
26 self.data.get_mut(&handle.id())
27 }
28
29 pub fn remove(&mut self, handle: &Handle<T>) -> Option<T> {
30 self.data.remove(&handle.id())
31 }
32
33 pub fn contains(&self, handle: &Handle<T>) -> bool {
34 self.data.contains_key(&handle.id())
35 }
36
37 pub fn len(&self) -> usize {
38 self.data.len()
39 }
40
41 pub fn is_empty(&self) -> bool {
42 self.data.is_empty()
43 }
44}
45
46impl<T> Default for Assets<T> {
47 fn default() -> Self {
48 Self::new()
49 }
50}