From 4dcbb7c94226884b9b68bf8339b940dea115f403 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Thu, 11 Sep 2025 11:39:53 -0300 Subject: [PATCH] feat: Add `ProgramWriter` utility struct for plugin communication Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) --- src/plugin.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/plugin.rs b/src/plugin.rs index e69de29..f6dc6aa 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -0,0 +1,25 @@ +use std::io::Write; + +use derive_more::{Deref, DerefMut}; + +/// A wrapper around a child process's stdin that implements the Write trait. +/// +/// This struct allows writing data to an external process's standard input +/// in a way that's compatible with Rust's I/O traits. +#[derive(Deref, DerefMut)] +pub struct ProgramWriter { + /// The stdin handle of a spawned child process + #[deref] + #[deref_mut] + pub stdin: std::process::ChildStdin, +} + +impl Write for ProgramWriter { + fn write(&mut self, buf: &[u8]) -> std::io::Result { + self.stdin.write(buf) + } + + fn flush(&mut self) -> std::io::Result<()> { + self.stdin.flush() + } +}