MCPcopy Create free account
hub / github.com/RetypeOS/parcode / register

Method register

src/compression.rs:374–389  ·  view source on GitHub ↗

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>)

Source from the content-addressed store, hash-verified

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 ///

Callers 1

newMethod · 0.80

Calls 2

idMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected