diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-08 20:35:58 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-08 20:35:58 -0500 |
commit | 9945a08434dc51d480d1e9303ee2fa7b5e823d7d (patch) | |
tree | 381928afb1f771c428c7d081dd5f70b9123687e7 | |
parent | 5dfd1f7a7734038eed310729e907313e7b499d68 (diff) | |
download | nbsh-9945a08434dc51d480d1e9303ee2fa7b5e823d7d.tar.gz nbsh-9945a08434dc51d480d1e9303ee2fa7b5e823d7d.zip |
simplify
-rw-r--r-- | src/shell/history/mod.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/shell/history/mod.rs b/src/shell/history/mod.rs index b2ad9d0..b7b33b8 100644 --- a/src/shell/history/mod.rs +++ b/src/shell/history/mod.rs @@ -492,11 +492,13 @@ async fn run_pipeline( nix::unistd::close(from_w)?; // Safety: to_w was just opened above, was not used until now, and can't - // be used after this because we rebound the variable - let mut to_w = unsafe { async_std::fs::File::from_raw_fd(to_w) }; - to_w.write_all(&bincode::serialize(pipeline)?).await?; - to_w.write_all(&env.as_bytes()).await?; - drop(to_w); + // be used after this because from_raw_fd takes it by move + write_env( + unsafe { async_std::fs::File::from_raw_fd(to_w) }, + pipeline, + env, + ) + .await?; let (read_w, read_r) = async_std::channel::unbounded(); let new_read = move || { @@ -579,3 +581,13 @@ async fn run_pipeline( } } } + +async fn write_env( + mut to_w: async_std::fs::File, + pipeline: &str, + env: &Env, +) -> anyhow::Result<()> { + to_w.write_all(&bincode::serialize(pipeline)?).await?; + to_w.write_all(&env.as_bytes()).await?; + Ok(()) +} |