(&mut self, value: T)
| 326 | /// returned via `Err(value)`. |
| 327 | #[inline] |
| 328 | pub fn try_alloc(&mut self, value: T) -> Result<Id, T> { |
| 329 | if let Some(index) = self.try_alloc_index() { |
| 330 | let next_free = match self.entries[index.index()] { |
| 331 | Entry::Free { next_free } => next_free, |
| 332 | Entry::Occupied { .. } => unreachable!(), |
| 333 | }; |
| 334 | self.free = next_free; |
| 335 | self.entries[index.index()] = Entry::Occupied(value); |
| 336 | self.len += 1; |
| 337 | Ok(Id(index)) |
| 338 | } else { |
| 339 | Err(value) |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | #[inline] |
| 344 | fn try_alloc_index(&mut self) -> Option<EntryIndex> { |
no test coverage detected