From e0337dbbb0a919d2bff3c22b90d0f0f17bad775d Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 29 Dec 2021 14:39:53 -0500 Subject: simplify --- examples/async-std.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'examples/async-std.rs') diff --git a/examples/async-std.rs b/examples/async-std.rs index 6bf9412..970841c 100644 --- a/examples/async-std.rs +++ b/examples/async-std.rs @@ -7,10 +7,13 @@ mod main { use async_std::prelude::FutureExt as _; pub async fn run( - child: &pty_process::Child, - ) -> std::result::Result<(), Box> { + child: &async_process::Child, + pty: &pty_process::Pty, + ) -> std::result::Result<(), Box> { let _raw = super::raw_guard::RawGuard::new(); + let mut input_pty = pty; + let mut output_pty = pty; let ex = async_executor::Executor::new(); let input = ex.spawn(async { @@ -19,7 +22,7 @@ mod main { loop { match stdin.read(&mut buf).await { Ok(bytes) => { - child.pty().write_all(&buf[..bytes]).await.unwrap(); + input_pty.write_all(&buf[..bytes]).await.unwrap(); } Err(e) => { eprintln!("stdin read failed: {:?}", e); @@ -32,7 +35,7 @@ mod main { let mut buf = [0_u8; 4096]; let mut stdout = async_std::io::stdout(); loop { - match child.pty().read(&mut buf).await { + match output_pty.read(&mut buf).await { Ok(bytes) => { stdout.write_all(&buf[..bytes]).await.unwrap(); stdout.flush().await.unwrap(); @@ -64,9 +67,9 @@ fn main() { pty.resize(pty_process::Size::new(24, 80)).unwrap(); let mut child = pty_process::Command::new("tac") // .args(&["500"]) - .spawn(pty) + .spawn(&pty) .unwrap(); - main::run(&child).await.unwrap(); + main::run(&child, &pty).await.unwrap(); child.status().await.unwrap() }); std::process::exit( -- cgit v1.2.3-54-g00ecf