agave_io_uring/
slab.rs

1use slab::Slab;
2
3pub struct FixedSlab<T> {
4    inner: Slab<T>,
5}
6
7impl<T> FixedSlab<T> {
8    pub fn with_capacity(cap: usize) -> Self {
9        Self {
10            inner: Slab::with_capacity(cap),
11        }
12    }
13
14    pub fn len(&self) -> usize {
15        self.inner.len()
16    }
17
18    pub fn capacity(&self) -> usize {
19        self.inner.capacity()
20    }
21
22    pub fn is_empty(&self) -> bool {
23        self.inner.is_empty()
24    }
25
26    pub fn is_full(&self) -> bool {
27        self.len() == self.capacity()
28    }
29
30    pub fn insert(&mut self, value: T) -> usize {
31        if self.is_full() {
32            panic!("FixedSlab is full, cannot insert new value");
33        }
34        self.inner.insert(value)
35    }
36
37    pub fn remove(&mut self, key: usize) -> T {
38        self.inner.remove(key)
39    }
40
41    pub fn get_mut(&mut self, key: usize) -> Option<&mut T> {
42        self.inner.get_mut(key)
43    }
44}