summaryrefslogtreecommitdiffstats
path: root/src/runner/builtins
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-02-26 18:08:40 -0500
committerJesse Luehrs <doy@tozt.net>2022-02-26 18:08:40 -0500
commitdfd5ebfa25d799399de0d15cb38ba47f5069647b (patch)
tree262c8b27621507bde8ab292bcd1b1fa04b44ca2f /src/runner/builtins
parent07ed5629fff12ccb95216f7b07c91bb6e8bbfbc7 (diff)
downloadnbsh-dfd5ebfa25d799399de0d15cb38ba47f5069647b.tar.gz
nbsh-dfd5ebfa25d799399de0d15cb38ba47f5069647b.zip
reduce typing
Diffstat (limited to 'src/runner/builtins')
-rw-r--r--src/runner/builtins/command.rs17
-rw-r--r--src/runner/builtins/mod.rs20
2 files changed, 17 insertions, 20 deletions
diff --git a/src/runner/builtins/command.rs b/src/runner/builtins/command.rs
index 85f6594..16d8b40 100644
--- a/src/runner/builtins/command.rs
+++ b/src/runner/builtins/command.rs
@@ -51,7 +51,7 @@ impl Command {
self.cfg.io.apply_redirects(redirects);
}
- pub fn spawn(self, env: &Env) -> anyhow::Result<Child> {
+ pub fn spawn(self, env: &Env) -> Result<Child> {
let Self { f, exe, cfg } = self;
(f)(exe, env, cfg)
}
@@ -187,7 +187,7 @@ impl Io {
}
}
- pub fn read_line_stdin(&self) -> anyhow::Result<(String, bool)> {
+ pub fn read_line_stdin(&self) -> Result<(String, bool)> {
let mut line = vec![];
if let Some(file) = self.stdin() {
if let File::In(fh) = &*file {
@@ -216,7 +216,7 @@ impl Io {
Ok((line, done))
}
- pub fn write_stdout(&self, buf: &[u8]) -> anyhow::Result<()> {
+ pub fn write_stdout(&self, buf: &[u8]) -> Result<()> {
if let Some(file) = self.stdout() {
if let File::Out(fh) = &*file {
Ok((&*fh).write_all(buf)?)
@@ -228,7 +228,7 @@ impl Io {
}
}
- pub fn write_stderr(&self, buf: &[u8]) -> anyhow::Result<()> {
+ pub fn write_stderr(&self, buf: &[u8]) -> Result<()> {
if let Some(file) = self.stderr() {
if let File::Out(fh) = &*file {
Ok((&*fh).write_all(buf)?)
@@ -358,17 +358,14 @@ impl Child {
self,
) -> std::pin::Pin<
Box<
- dyn std::future::Future<
- Output = anyhow::Result<std::process::ExitStatus>,
- > + Send
+ dyn std::future::Future<Output = Result<std::process::ExitStatus>>
+ + Send
+ Sync,
>,
> {
Box::pin(async move {
match self {
- Self::Task(task) => {
- task.await.map_err(|e| anyhow::anyhow!(e))
- }
+ Self::Task(task) => task.await.map_err(|e| anyhow!(e)),
Self::Wrapped(child) => child.status().await,
}
})
diff --git a/src/runner/builtins/mod.rs b/src/runner/builtins/mod.rs
index f212496..862f5b0 100644
--- a/src/runner/builtins/mod.rs
+++ b/src/runner/builtins/mod.rs
@@ -7,7 +7,7 @@ type Builtin = &'static (dyn for<'a> Fn(
crate::parse::Exe,
&'a Env,
command::Cfg,
-) -> anyhow::Result<command::Child>
+) -> Result<command::Child>
+ Sync
+ Send);
@@ -54,7 +54,7 @@ fn cd(
exe: crate::parse::Exe,
env: &Env,
cfg: command::Cfg,
-) -> anyhow::Result<command::Child> {
+) -> Result<command::Child> {
let prev_pwd = env.prev_pwd();
let home = env.var("HOME");
Ok(command::Child::new_task(move || {
@@ -92,7 +92,7 @@ fn set(
exe: crate::parse::Exe,
_env: &Env,
cfg: command::Cfg,
-) -> anyhow::Result<command::Child> {
+) -> Result<command::Child> {
Ok(command::Child::new_task(move || {
let k = if let Some(k) = exe.args().get(0).map(String::as_str) {
k
@@ -115,7 +115,7 @@ fn unset(
exe: crate::parse::Exe,
_env: &Env,
cfg: command::Cfg,
-) -> anyhow::Result<command::Child> {
+) -> Result<command::Child> {
Ok(command::Child::new_task(move || {
let k = if let Some(k) = exe.args().get(0).map(String::as_str) {
k
@@ -136,7 +136,7 @@ fn echo(
exe: crate::parse::Exe,
_env: &Env,
cfg: command::Cfg,
-) -> anyhow::Result<command::Child> {
+) -> Result<command::Child> {
Ok(command::Child::new_task(move || {
macro_rules! write_stdout {
($bytes:expr) => {
@@ -167,7 +167,7 @@ fn read(
exe: crate::parse::Exe,
_env: &Env,
cfg: command::Cfg,
-) -> anyhow::Result<command::Child> {
+) -> Result<command::Child> {
Ok(command::Child::new_task(move || {
let var = if let Some(var) = exe.args().get(0).map(String::as_str) {
var
@@ -191,7 +191,7 @@ fn and(
mut exe: crate::parse::Exe,
env: &Env,
cfg: command::Cfg,
-) -> anyhow::Result<command::Child> {
+) -> Result<command::Child> {
exe.shift();
if env.latest_status().success() {
let mut cmd = crate::runner::Command::new(exe, cfg.io().clone());
@@ -207,7 +207,7 @@ fn or(
mut exe: crate::parse::Exe,
env: &Env,
cfg: command::Cfg,
-) -> anyhow::Result<command::Child> {
+) -> Result<command::Child> {
exe.shift();
if env.latest_status().success() {
let status = env.latest_status();
@@ -223,7 +223,7 @@ fn command(
mut exe: crate::parse::Exe,
env: &Env,
cfg: command::Cfg,
-) -> anyhow::Result<command::Child> {
+) -> Result<command::Child> {
exe.shift();
let mut cmd = crate::runner::Command::new_binary(exe);
cfg.setup_command(&mut cmd);
@@ -234,7 +234,7 @@ fn builtin(
mut exe: crate::parse::Exe,
env: &Env,
cfg: command::Cfg,
-) -> anyhow::Result<command::Child> {
+) -> Result<command::Child> {
exe.shift();
let mut cmd = crate::runner::Command::new_builtin(exe, cfg.io().clone());
cfg.setup_command(&mut cmd);