ainl_runtime/adapters/
mod.rs1mod graph_patch;
4
5pub use graph_patch::{GraphPatchAdapter, GraphPatchHostDispatch};
6
7use std::collections::HashMap;
8
9use crate::engine::PatchDispatchContext;
10
11pub trait PatchAdapter: Send + Sync {
16 fn name(&self) -> &str;
18
19 fn execute_patch(&self, ctx: &PatchDispatchContext<'_>) -> Result<serde_json::Value, String>;
24}
25
26#[derive(Default)]
27pub struct AdapterRegistry {
28 adapters: HashMap<String, Box<dyn PatchAdapter>>,
29}
30
31impl AdapterRegistry {
32 pub fn new() -> Self {
33 Self::default()
34 }
35
36 pub fn register(&mut self, adapter: impl PatchAdapter + 'static) {
37 self.adapters
38 .insert(adapter.name().to_string(), Box::new(adapter));
39 }
40
41 pub fn get(&self, label: &str) -> Option<&dyn PatchAdapter> {
42 self.adapters.get(label).map(|boxed| boxed.as_ref())
43 }
44
45 pub fn registered_names(&self) -> Vec<&str> {
46 let mut names: Vec<&str> = self.adapters.keys().map(|s| s.as_str()).collect();
47 names.sort_unstable();
48 names
49 }
50
51 pub fn is_empty(&self) -> bool {
52 self.adapters.is_empty()
53 }
54}