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
21 .insert(key, Box::new(|| Box::new(S::default())));
22 }
23
24 pub fn register_factory(
26 &mut self,
27 key: &str,
28 factory: impl Fn() -> Box<dyn StepBody> + Send + Sync + 'static,
29 ) {
30 self.factories.insert(key.to_string(), Box::new(factory));
31 }
32
33 pub fn resolve(&self, step_type: &str) -> Option<Box<dyn StepBody>> {
35 self.factories.get(step_type).map(|f| f())
36 }
37}
38
39impl Default for StepRegistry {
40 fn default() -> Self {
41 Self::new()
42 }
43}