refactor: move ProgramWriter to common.rs

This commit is contained in:
Andrew Phillips (aider)
2025-05-22 09:48:19 -03:00
parent beef2e773e
commit e1a5dbf0f1
5 changed files with 19 additions and 32 deletions

15
src/common.rs Normal file
View File

@@ -0,0 +1,15 @@
use std::io::Write;
pub struct ProgramWriter {
stdin: std::process::ChildStdin,
}
impl Write for ProgramWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.stdin.write(buf)
}
fn flush(&mut self) -> std::io::Result<()> {
self.stdin.flush()
}
}

View File

@@ -38,21 +38,6 @@ pub trait DigestEngine {
use std::io::Write; use std::io::Write;
// Writer that implements Write for the program digest engine
struct ProgramWriter {
stdin: std::process::ChildStdin,
}
impl Write for ProgramWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.stdin.write(buf)
}
fn flush(&mut self) -> std::io::Result<()> {
self.stdin.flush()
}
}
lazy_static! { lazy_static! {
pub static ref DIGEST_PROGRAMS: EnumMap<DigestType, Option<DigestEngineProgram>> = enum_map! { pub static ref DIGEST_PROGRAMS: EnumMap<DigestType, Option<DigestEngineProgram>> = enum_map! {
DigestType::Sha256 => None, DigestType::Sha256 => None,

View File

@@ -1,4 +1,4 @@
use crate::digest_engine::ProgramWriter; use crate::common::ProgramWriter;
use anyhow::{Context, Result, anyhow}; use anyhow::{Context, Result, anyhow};
use log::*; use log::*;
use std::env; use std::env;

View File

@@ -35,21 +35,6 @@ pub trait MetaPlugin {
use std::io::Write; use std::io::Write;
// Writer that implements Write for the program meta plugin
struct ProgramWriter {
stdin: std::process::ChildStdin,
}
impl Write for ProgramWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.stdin.write(buf)
}
fn flush(&mut self) -> std::io::Result<()> {
self.stdin.flush()
}
}
lazy_static! { lazy_static! {
pub static ref META_PLUGIN_PROGRAMS: EnumMap<MetaPluginType, Option<MetaPluginProgram>> = enum_map! { pub static ref META_PLUGIN_PROGRAMS: EnumMap<MetaPluginType, Option<MetaPluginProgram>> = enum_map! {
MetaPluginType::File => { MetaPluginType::File => {

View File

@@ -1,4 +1,4 @@
use crate::meta_plugin::MetaPlugin; use crate::common::ProgramWriter;
use anyhow::{Context, Result, anyhow}; use anyhow::{Context, Result, anyhow};
use log::*; use log::*;
use std::env; use std::env;
@@ -8,6 +8,8 @@ use std::io::Write;
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use crate::meta_plugin::MetaPlugin;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MetaPluginProgram { pub struct MetaPluginProgram {
pub program: String, pub program: String,