From 9123d63343b1ece4926782232bcc15db9554fc90 Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Sat, 14 Apr 2018 04:53:18 -0400 Subject: [PATCH] Express filter as a future --- src/commands/filter.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/commands/filter.rs b/src/commands/filter.rs index c3a4839..663a2bb 100644 --- a/src/commands/filter.rs +++ b/src/commands/filter.rs @@ -5,7 +5,7 @@ use std::{ }; use clap::{App, Arg, ArgMatches, SubCommand}; -use futures::Stream; +use futures::prelude::*; use super::StdinStream; use webmetro::{ @@ -40,11 +40,8 @@ pub fn run(args: &ArgMatches) -> Result<(), Box> { chunk_stream = Box::new(chunk_stream.throttle()); } - let stdout = io::stdout(); - let mut stdout_writer = stdout.lock(); - for chunk in chunk_stream.wait() { - stdout_writer.write_all(chunk?.as_ref())?; - } - - Ok(()) + let result = chunk_stream.fold((), |_, chunk| { + io::stdout().write_all(chunk.as_ref()) + }).wait(); + result }