1use slotmap::SlotMap;
2
3pub struct Arena<K: slotmap::Key, V> {
5 inner: SlotMap<K, V>,
6}
7
8impl<K: slotmap::Key, V> Default for Arena<K, V> {
9 fn default() -> Self {
10 Self { inner: SlotMap::with_key() }
11 }
12}
13
14impl<K: slotmap::Key, V> Arena<K, V> {
15 pub fn new() -> Self {
16 Self::default()
17 }
18 pub fn insert(&mut self, value: V) -> K {
19 self.inner.insert(value)
20 }
21 pub fn get(&self, id: K) -> Option<&V> {
22 self.inner.get(id)
23 }
24 pub fn get_mut(&mut self, id: K) -> Option<&mut V> {
25 self.inner.get_mut(id)
26 }
27 pub fn remove(&mut self, id: K) -> Option<V> {
28 self.inner.remove(id)
29 }
30 pub fn contains(&self, id: K) -> bool {
31 self.inner.contains_key(id)
32 }
33 pub fn len(&self) -> usize {
34 self.inner.len()
35 }
36 pub fn is_empty(&self) -> bool {
37 self.inner.is_empty()
38 }
39 pub fn iter(&self) -> impl Iterator<Item = (K, &V)> {
41 self.inner.iter()
42 }
43}
44
45