Registers a new compressor. The compressor's ID (returned by `algo.id()`) determines its slot in the registry. If a compressor with the same ID is already registered, it will be overwritten.
(&mut self, algo: Box<dyn Compressor>)
| 372 | /// The compressor's ID (returned by `algo.id()`) determines its slot in the registry. |
| 373 | /// If a compressor with the same ID is already registered, it will be overwritten. |
| 374 | pub fn register(&mut self, algo: Box<dyn Compressor>) { |
| 375 | let id = algo.id() as usize; |
| 376 | |
| 377 | // Ensure the vector is large enough to hold the new ID. |
| 378 | if id >= self.algorithms.len() { |
| 379 | self.algorithms.resize_with(id + 1, || None); |
| 380 | } |
| 381 | |
| 382 | // `resize_with` guarantees the index is valid. |
| 383 | let slot = self |
| 384 | .algorithms |
| 385 | .get_mut(id) |
| 386 | .expect("Registry vector resized but index not found. This is a bug."); |
| 387 | |
| 388 | *slot = Some(algo); |
| 389 | } |
| 390 | |
| 391 | /// Retrieves a compressor by its ID. |
| 392 | /// |