use std::collections::HashMap; use anyhow::Error; use giterated_api::DaemonConnectionPool; use giterated_models::model::instance::Instance; #[derive(Default)] pub struct InstanceConnections { pools: HashMap, } impl InstanceConnections { pub fn get_or_open(&mut self, instance: &Instance) -> Result { if let Some(pool) = self.pools.get(instance) { Ok(pool.clone()) } else { let pool = DaemonConnectionPool::connect(instance.clone()).unwrap(); self.pools.insert(instance.clone(), pool.clone()); Ok(pool) } } }