mod graph_patch;
pub use graph_patch::{GraphPatchAdapter, GraphPatchHostDispatch};
use std::collections::HashMap;
use crate::engine::PatchDispatchContext;
pub trait PatchAdapter: Send + Sync {
fn name(&self) -> &str;
fn execute_patch(&self, ctx: &PatchDispatchContext<'_>) -> Result<serde_json::Value, String>;
}
#[derive(Default)]
pub struct AdapterRegistry {
adapters: HashMap<String, Box<dyn PatchAdapter>>,
}
impl AdapterRegistry {
pub fn new() -> Self {
Self::default()
}
pub fn register(&mut self, adapter: impl PatchAdapter + 'static) {
self.adapters
.insert(adapter.name().to_string(), Box::new(adapter));
}
pub fn get(&self, label: &str) -> Option<&dyn PatchAdapter> {
self.adapters.get(label).map(|boxed| boxed.as_ref())
}
pub fn registered_names(&self) -> Vec<&str> {
let mut names: Vec<&str> = self.adapters.keys().map(|s| s.as_str()).collect();
names.sort_unstable();
names
}
pub fn is_empty(&self) -> bool {
self.adapters.is_empty()
}
}