aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-07-09 03:14:26 -0400
committerJesse Luehrs <doy@tozt.net>2019-07-09 03:14:26 -0400
commit2510f46e32ade9f7c3f6d2546e8a7338f4c27cd7 (patch)
treeb9cfd00badd10e9805e676ad2c3ea638c032694e
parent4f593b410b7d66a8f5e2d0e970f59854938926a7 (diff)
downloadnbsh-old-2510f46e32ade9f7c3f6d2546e8a7338f4c27cd7.tar.gz
nbsh-old-2510f46e32ade9f7c3f6d2546e8a7338f4c27cd7.zip
use context instead of map_err for futures and streams
-rw-r--r--Cargo.lock10
-rw-r--r--Cargo.toml2
-rw-r--r--src/eval.rs14
-rw-r--r--src/repl.rs5
-rw-r--r--src/state.rs2
-rw-r--r--src/tui.rs9
6 files changed, 22 insertions, 20 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a3c245f..67825a7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -229,6 +229,14 @@ version = "0.1.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "futures01"
+version = "0.1.27"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "iovec"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -578,6 +586,7 @@ version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"backtrace 0.3.30 (registry+https://github.com/rust-lang/crates.io-index)",
+ "futures01 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
"snafu-derive 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -891,6 +900,7 @@ dependencies = [
"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
"checksum futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "a2037ec1c6c1c4f79557762eab1f7eae1f64f6cb418ace90fae88f0942b60139"
+"checksum futures01 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "289b17fb9d2d82f689a3ef11b11d402da2c583c30bb142d529bd06f0ecff1a4e"
"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08"
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
diff --git a/Cargo.toml b/Cargo.toml
index 6792a5e..a7a6deb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,6 +15,6 @@ crossterm = "0.9"
futures = "0.1"
mio = "0.6"
nix = "0.14"
-snafu = "0.4"
+snafu = { version = "0.4", features = ["futures-01"] }
tokio = "0.1"
tokio-pty-process = "0.4"
diff --git a/src/eval.rs b/src/eval.rs
index 549650d..af3de9e 100644
--- a/src/eval.rs
+++ b/src/eval.rs
@@ -1,4 +1,4 @@
-use futures::stream::Stream as _;
+use snafu::futures01::StreamExt as _;
use snafu::ResultExt as _;
#[derive(Debug, snafu::Snafu)]
@@ -56,19 +56,11 @@ impl Eval {
dyn futures::stream::Stream<Item = CommandEvent, Error = Error>
+ Send,
> = if let Ok(s) = builtin_stream {
- Box::new(s.map_err(move |e| Error::BuiltinExecution {
- cmd: cmd.clone(),
- source: e,
- }))
+ Box::new(s.context(BuiltinExecution { cmd }))
} else {
let process_stream = crate::process::spawn(&cmd, &args);
match process_stream {
- Ok(s) => {
- Box::new(s.map_err(move |e| Error::ProcessExecution {
- cmd: cmd.clone(),
- source: e,
- }))
- }
+ Ok(s) => Box::new(s.context(ProcessExecution { cmd })),
Err(e) => {
return Err(e).context(Command { cmd });
}
diff --git a/src/repl.rs b/src/repl.rs
index aa80132..cac6649 100644
--- a/src/repl.rs
+++ b/src/repl.rs
@@ -1,5 +1,6 @@
use futures::future::{Future as _, IntoFuture as _};
use futures::stream::Stream as _;
+use snafu::futures01::{FutureExt as _, StreamExt as _};
use snafu::ResultExt as _;
use std::io::Write as _;
@@ -53,7 +54,7 @@ fn read() -> impl futures::future::Future<Item = String, Error = Error> {
crate::readline::readline("$ ", true)
.into_future()
.flatten()
- .map_err(|e| Error::Read { source: e })
+ .context(Read)
}
fn eval(
@@ -63,7 +64,7 @@ fn eval(
crate::eval::eval(line)
.into_future()
.flatten_stream()
- .map_err(|e| Error::Eval { source: e })
+ .context(Eval)
}
fn print(event: &crate::eval::CommandEvent) -> Result<()> {
diff --git a/src/state.rs b/src/state.rs
index 652911c..b9707c0 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -136,7 +136,7 @@ impl futures::future::Future for State {
.unwrap()
.future
.poll()
- .map_err(|e| Error::Eval { source: e })?
+ .context(Eval)?
{
futures::Async::Ready(Some(event)) => match event {
crate::eval::CommandEvent::CommandStart(
diff --git a/src/tui.rs b/src/tui.rs
index 88a169d..b7af752 100644
--- a/src/tui.rs
+++ b/src/tui.rs
@@ -1,5 +1,6 @@
use futures::future::{Future as _, IntoFuture as _};
use futures::sink::Sink as _;
+use snafu::futures01::FutureExt as _;
use std::io::Write as _;
#[derive(Debug, snafu::Snafu)]
@@ -38,10 +39,8 @@ pub fn tui() {
.and_then(move |line| {
let (res, req) = futures::sync::oneshot::channel();
w.send(crate::state::StateEvent::Line(idx, line, res))
- .map_err(|e| Error::Sending { source: e })
- .and_then(|_| {
- req.map_err(|e| Error::Receiving { source: e })
- })
+ .context(Sending)
+ .and_then(|_| req.context(Receiving))
})
.then(move |res| match res {
// successful run or empty input means prompt again
@@ -72,7 +71,7 @@ fn read() -> impl futures::future::Future<Item = String, Error = Error> {
crate::readline::readline("$ ", true)
.into_future()
.flatten()
- .map_err(|e| Error::Read { source: e })
+ .context(Read)
}
fn error(e: &Error) {