wfe_core/executor/
step_registry.rs1use std::collections::HashMap;
2
3use crate::traits::StepBody;
4
5pub struct StepRegistry {
7 factories: HashMap<String, Box<dyn Fn() -> Box<dyn StepBody> + Send + Sync>>,
8}
9
10impl StepRegistry {
11 pub fn new() -> Self {
12 Self {
13 factories: HashMap::new(),
14 }
15 }
16
17 pub fn register<S: StepBody + Default + 'static>(&mut self) {
19 let key = std::any::type_name::<S>().to_string();
20 self.factories.insert(key, Box::new(|| Box::new(S::default())));
21 }
22
23 pub fn register_factory(
25 &mut self,
26 key: &str,
27 factory: impl Fn() -> Box<dyn StepBody> + Send + Sync + 'static,
28 ) {
29 self.factories.insert(key.to_string(), Box::new(factory));
30 }
31
32 pub fn resolve(&self, step_type: &str) -> Option<Box<dyn StepBody>> {
34 self.factories.get(step_type).map(|f| f())
35 }
36}
37
38impl Default for StepRegistry {
39 fn default() -> Self {
40 Self::new()
41 }
42}