datasources 0.1.25

Async datasource interfaces, middleware, registry, and test doubles
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::driver::Driver;
use std::collections::HashMap;
use std::sync::{Arc, Mutex, MutexGuard};

pub struct FactoryPair {
    pub driver: Arc<dyn Driver>,
}

static REGISTRY: Mutex<Option<HashMap<String, FactoryPair>>> = Mutex::new(None);

pub(crate) fn registry() -> MutexGuard<'static, Option<HashMap<String, FactoryPair>>> {
    REGISTRY.lock().expect("registry")
}

pub(crate) fn registered_driver(name: &str) -> Option<Arc<dyn Driver>> {
    registry().as_ref()?.get(name).map(|pair| pair.driver.clone())
}