use async_trait::async_trait; use bytes::{Bytes, BytesMut}; use std::env; use std::io; use std::process; use tokio_hglib::{PipeClient, UiHandler}; struct BufferedUiHandler { buf: BytesMut, } #[async_trait] impl UiHandler for BufferedUiHandler { async fn read_data(&mut self, _len: usize) -> io::Result { Ok(Bytes::new()) // EOF } async fn read_line(&mut self, _len: usize) -> io::Result { Ok(Bytes::new()) // EOF } async fn write_output(&mut self, data: Bytes) -> io::Result<()> { self.buf.extend(data); Ok(()) } async fn write_error(&mut self, data: Bytes) -> io::Result<()> { self.buf.extend(data); Ok(()) } } #[tokio::main(flavor = "current_thread")] async fn run() -> io::Result { let mut handler = BufferedUiHandler { buf: BytesMut::new(), }; let mut client = PipeClient::spawn_at(".").await?; let code = client .run_command(&mut handler, env::args().skip(1)) .await?; println!("received:\n{:?}", handler.buf); Ok(code) } fn main() -> io::Result<()> { let code = run()?; process::exit(code); }