refactor: update empty hashmap initialization with lazy initialization

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-26 18:06:50 -03:00
parent 3fb436dc44
commit 1d463323ce
5 changed files with 13 additions and 8 deletions

View File

@@ -196,7 +196,9 @@ pub trait MetaPlugin {
// Access to outputs mapping with default implementation // Access to outputs mapping with default implementation
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
static EMPTY: std::collections::HashMap<String, serde_yaml::Value> = std::collections::HashMap::new(); use once_cell::sync::Lazy;
static EMPTY: Lazy<std::collections::HashMap<String, serde_yaml::Value>> =
Lazy::new(|| std::collections::HashMap::new());
&EMPTY &EMPTY
} }
@@ -206,7 +208,9 @@ pub trait MetaPlugin {
// Access to options mapping with default implementation // Access to options mapping with default implementation
fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value> { fn options(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
static EMPTY: std::collections::HashMap<String, serde_yaml::Value> = std::collections::HashMap::new(); use once_cell::sync::Lazy;
static EMPTY: Lazy<std::collections::HashMap<String, serde_yaml::Value>> =
Lazy::new(|| std::collections::HashMap::new());
&EMPTY &EMPTY
} }

View File

@@ -69,9 +69,10 @@ impl MetaPlugin for BinaryMetaPlugin {
} }
} }
let is_finalized = !metadata.is_empty();
MetaPluginResponse { MetaPluginResponse {
metadata, metadata,
is_finalized: !metadata.is_empty(), is_finalized,
} }
} }
@@ -121,7 +122,7 @@ impl MetaPlugin for BinaryMetaPlugin {
self.base.options_mut() self.base.options_mut()
} }
fn configure_options(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> { fn configure_options(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> anyhow::Result<()> {
if let Some(max_buffer_size) = options.get("max_buffer_size") { if let Some(max_buffer_size) = options.get("max_buffer_size") {
if let Some(size) = max_buffer_size.as_u64() { if let Some(size) = max_buffer_size.as_u64() {
self.max_buffer_size = size as usize; self.max_buffer_size = size as usize;

View File

@@ -182,7 +182,7 @@ impl MetaPlugin for MagicFileMetaPlugin {
"magic_file".to_string() "magic_file".to_string()
} }
fn configure_options(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> { fn configure_options(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> anyhow::Result<()> {
if let Some(max_buffer_size) = options.get("max_buffer_size") { if let Some(max_buffer_size) = options.get("max_buffer_size") {
if let Some(size) = max_buffer_size.as_u64() { if let Some(size) = max_buffer_size.as_u64() {
self.max_buffer_size = size as usize; self.max_buffer_size = size as usize;

View File

@@ -162,9 +162,10 @@ impl MetaPlugin for MetaPluginProgram {
self.result = Some(result); self.result = Some(result);
// Create metadata to be returned // Create metadata to be returned
let result_clone = result.clone();
metadata.push(crate::meta_plugin::MetaData { metadata.push(crate::meta_plugin::MetaData {
name: self.meta_name.clone(), name: self.meta_name.clone(),
value: result, value: result_clone,
}); });
} }
} else { } else {

View File

@@ -1,8 +1,7 @@
use gethostname::gethostname; use gethostname::gethostname;
use std::env; use std::env;
use std::process; use std::process;
use uzers::{get_current_uid, get_current_gid, get_user_by_uid, get_group_by_gid}; use crate::meta_plugin::MetaPlugin;
use crate::meta_plugin::{MetaPlugin, MetaPluginResponse};
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct CwdMetaPlugin { pub struct CwdMetaPlugin {