remotia_buffer_utils/
pool_registry.rs1use std::{collections::{hash_map::Keys, HashMap}, hash::Hash, fmt::Debug};
2
3use crate::pool::BuffersPool;
4
5pub struct PoolRegistry<K: Copy + PartialEq + Eq + Hash> {
6 pools: HashMap<K, BuffersPool<K>>,
7}
8
9impl<K: Copy + PartialEq + Eq + Hash + Debug> PoolRegistry<K> {
10 pub fn new() -> Self {
11 Self {
12 pools: HashMap::new(),
13 }
14 }
15
16 pub async fn register(&mut self, slot_id: K, pool_size: usize, buffer_size: usize) {
17 let pool = BuffersPool::new(slot_id, pool_size, buffer_size).await;
18 self.pools.insert(slot_id, pool);
19 }
20
21 pub fn get(&self, slot_id: K) -> &BuffersPool<K> {
22 self.pools.get(&slot_id).expect(&format!(
23 "No pool with ID {:?} found in the registry",
24 slot_id
25 ))
26 }
27
28 pub fn get_buffer_ids(&self) -> Keys<K, BuffersPool<K>> {
52 self.pools.keys()
53 }
54}