From a2462bbaea13f7a3f3eb65e7430b30618bc203b8 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 25 Feb 2022 17:32:58 -0500 Subject: move to tokio --- src/parse/ast.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'src/parse') diff --git a/src/parse/ast.rs b/src/parse/ast.rs index e2d5840..46aa63a 100644 --- a/src/parse/ast.rs +++ b/src/parse/ast.rs @@ -97,7 +97,7 @@ impl Pipeline { .into_iter() .map(|exe| exe.eval(env)) .collect::>() - .collect::>() + .try_collect() .await?, }) } @@ -137,7 +137,7 @@ impl Exe { arg.eval(env).await.map(IntoIterator::into_iter) }) .collect::>() - .collect::, _>>() + .try_collect::>() .await? .into_iter() .flatten() @@ -147,7 +147,7 @@ impl Exe { .into_iter() .map(|arg| arg.eval(env)) .collect::>() - .collect::>() + .try_collect() .await?, }) } @@ -330,12 +330,12 @@ impl WordPart { match self { Self::Alternation(_) => unreachable!(), Self::Substitution(commands) => { - let mut cmd = async_std::process::Command::new( + let mut cmd = tokio::process::Command::new( std::env::current_exe().unwrap(), ); cmd.args(&["-c", &commands]); - cmd.stdin(async_std::process::Stdio::inherit()); - cmd.stderr(async_std::process::Stdio::inherit()); + cmd.stdin(std::process::Stdio::inherit()); + cmd.stderr(std::process::Stdio::inherit()); let mut out = String::from_utf8(cmd.output().await.unwrap().stdout) .unwrap(); @@ -408,15 +408,20 @@ impl Redirect { let mut iter = pair.into_inner(); let prefix = iter.next().unwrap().as_str(); - let (from, dir) = if let Some(from) = prefix.strip_suffix(">>") { - (from, super::Direction::Append) - } else if let Some(from) = prefix.strip_suffix('>') { - (from, super::Direction::Out) - } else if let Some(from) = prefix.strip_suffix('<') { - (from, super::Direction::In) - } else { - unreachable!() - }; + let (from, dir) = prefix.strip_suffix(">>").map_or_else( + || { + prefix.strip_suffix('>').map_or_else( + || { + ( + prefix.strip_suffix('<').unwrap(), + super::Direction::In, + ) + }, + |from| (from, super::Direction::Out), + ) + }, + |from| (from, super::Direction::Append), + ); let from = if from.is_empty() { match dir { super::Direction::In => 0, -- cgit v1.2.3-54-g00ecf