refactor: reduce boilerplate by using default implementations and base struct
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -29,6 +29,37 @@ pub struct MetaPluginResponse {
|
||||
pub is_finalized: bool,
|
||||
}
|
||||
|
||||
/// Base implementation for meta plugins to reduce boilerplate
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct BaseMetaPlugin {
|
||||
pub outputs: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
pub options: std::collections::HashMap<String, serde_yaml::Value>,
|
||||
}
|
||||
|
||||
impl BaseMetaPlugin {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
}
|
||||
|
||||
impl MetaPlugin for BaseMetaPlugin {
|
||||
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.outputs
|
||||
}
|
||||
|
||||
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&mut self.outputs
|
||||
}
|
||||
|
||||
fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&self.options
|
||||
}
|
||||
|
||||
fn options_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&mut self.options
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone, strum::EnumIter, strum::Display, strum::EnumString)]
|
||||
#[strum(ascii_case_insensitive)]
|
||||
pub enum MetaPluginType {
|
||||
@@ -93,7 +124,7 @@ pub trait MetaPlugin {
|
||||
}
|
||||
|
||||
// Update the meta plugin with new data
|
||||
fn update(&mut self, data: &[u8]) -> MetaPluginResponse {
|
||||
fn update(&mut self, _data: &[u8]) -> MetaPluginResponse {
|
||||
// Default implementation does nothing
|
||||
MetaPluginResponse {
|
||||
metadata: Vec::new(),
|
||||
@@ -125,13 +156,23 @@ pub trait MetaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
// Access to outputs mapping
|
||||
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value>;
|
||||
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value>;
|
||||
// Access to outputs mapping with default implementation
|
||||
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&std::collections::HashMap::new()
|
||||
}
|
||||
|
||||
// Access to options mapping
|
||||
fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value>;
|
||||
fn options_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value>;
|
||||
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
|
||||
panic!("outputs_mut() not implemented for this plugin")
|
||||
}
|
||||
|
||||
// Access to options mapping with default implementation
|
||||
fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
|
||||
&std::collections::HashMap::new()
|
||||
}
|
||||
|
||||
fn options_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
|
||||
panic!("options_mut() not implemented for this plugin")
|
||||
}
|
||||
|
||||
// Get the default output names this plugin can produce
|
||||
fn default_outputs(&self) -> Vec<String> {
|
||||
|
||||
Reference in New Issue
Block a user