Allocate a handle for the given item. Returns a 1-based index as f64.
(&mut self, item: T)
| 15 | |
| 16 | /// Allocate a handle for the given item. Returns a 1-based index as f64. |
| 17 | pub fn alloc(&mut self, item: T) -> f64 { |
| 18 | if let Some(idx) = self.free_list.pop() { |
| 19 | self.items[idx] = Some(item); |
| 20 | (idx + 1) as f64 |
| 21 | } else { |
| 22 | self.items.push(Some(item)); |
| 23 | self.items.len() as f64 |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | /// Get a reference to the item at the given handle. |
| 28 | pub fn get(&self, handle: f64) -> Option<&T> { |
no test coverage detected