Push a new entry into the table, returning its handle. This will prefer to use free entries if they exist, falling back on pushing new entries onto the end of the table.
(&mut self, e: TableEntry)
| 213 | /// Push a new entry into the table, returning its handle. This will prefer to use free entries |
| 214 | /// if they exist, falling back on pushing new entries onto the end of the table. |
| 215 | fn push_(&mut self, e: TableEntry) -> Result<u32, ResourceTableError> { |
| 216 | if let Some(free) = self.pop_free_list() { |
| 217 | self.entries[free] = Entry::Occupied { entry: e }; |
| 218 | Ok(free.try_into().unwrap()) |
| 219 | } else { |
| 220 | if self.entries.len() >= self.max_capacity { |
| 221 | return Err(ResourceTableError::Full); |
| 222 | } |
| 223 | let ix = self |
| 224 | .entries |
| 225 | .len() |
| 226 | .try_into() |
| 227 | .map_err(|_| ResourceTableError::Full)?; |
| 228 | self.entries.push(Entry::Occupied { entry: e }); |
| 229 | Ok(ix) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | fn occupied(&self, key: u32) -> Result<&TableEntry, ResourceTableError> { |
| 234 | self.entries |