refactor: move ProgramWriter to common.rs
This commit is contained in:
15
src/common.rs
Normal file
15
src/common.rs
Normal 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()
|
||||
}
|
||||
}
|
||||
@@ -38,21 +38,6 @@ pub trait DigestEngine {
|
||||
|
||||
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! {
|
||||
pub static ref DIGEST_PROGRAMS: EnumMap<DigestType, Option<DigestEngineProgram>> = enum_map! {
|
||||
DigestType::Sha256 => None,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::digest_engine::ProgramWriter;
|
||||
use crate::common::ProgramWriter;
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use log::*;
|
||||
use std::env;
|
||||
|
||||
@@ -35,21 +35,6 @@ pub trait MetaPlugin {
|
||||
|
||||
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! {
|
||||
pub static ref META_PLUGIN_PROGRAMS: EnumMap<MetaPluginType, Option<MetaPluginProgram>> = enum_map! {
|
||||
MetaPluginType::File => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::meta_plugin::MetaPlugin;
|
||||
use crate::common::ProgramWriter;
|
||||
use anyhow::{Context, Result, anyhow};
|
||||
use log::*;
|
||||
use std::env;
|
||||
@@ -8,6 +8,8 @@ use std::io::Write;
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
use crate::meta_plugin::MetaPlugin;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MetaPluginProgram {
|
||||
pub program: String,
|
||||
|
||||
Reference in New Issue
Block a user