use std::sync::Arc;
use rustc_hash::FxHashMap;
use crate::step::StepParam;
pub struct CustomParamType {
pub name: String,
pub regex: String,
pub transformer: Option<Arc<dyn Fn(&str) -> StepParam + Send + Sync>>,
}
pub struct ParameterTypeRegistry {
types: FxHashMap<String, CustomParamType>,
}
impl ParameterTypeRegistry {
pub fn new() -> Self {
Self {
types: FxHashMap::default(),
}
}
pub fn register(&mut self, param_type: CustomParamType) {
self.types.insert(param_type.name.clone(), param_type);
}
pub fn find(&self, name: &str) -> Option<&CustomParamType> {
self.types.get(name)
}
pub fn is_empty(&self) -> bool {
self.types.is_empty()
}
}
impl Default for ParameterTypeRegistry {
fn default() -> Self {
Self::new()
}
}
pub struct ParameterTypeRegistration {
pub name: &'static str,
pub regex: &'static str,
pub transformer_factory: Option<fn() -> Arc<dyn Fn(&str) -> StepParam + Send + Sync>>,
}
inventory::collect!(ParameterTypeRegistration);