use lazy_static::lazy_static;
use std::{collections::HashMap, sync::RwLock};
pub type KeyTemplateGenerator = fn() -> tink_proto::KeyTemplate;
lazy_static! {
static ref TEMPLATE_GENERATORS: RwLock<HashMap<String, KeyTemplateGenerator>> =
RwLock::new(HashMap::new());
}
pub fn register_template_generator(name: &str, generator: KeyTemplateGenerator) {
TEMPLATE_GENERATORS
.write()
.unwrap() .insert(name.to_string(), generator);
}
pub fn get_template_generator(name: &str) -> Option<KeyTemplateGenerator> {
TEMPLATE_GENERATORS.read().unwrap().get(name).copied() }
pub fn template_names() -> Vec<String> {
TEMPLATE_GENERATORS
.read()
.unwrap() .keys()
.cloned()
.collect()
}