From d8efc6e40af328d10cdeff7eb5a972412e75d13a Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 17 May 2021 11:54:28 +0100 Subject: [PATCH] progress: Make cmd_withbulk take termprogress::Reporter, not a Fn Signed-off-by: Ian Jackson --- src/bin/otter.rs | 8 +++----- src/mgmtchannel.rs | 13 +++++++------ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index dcac0d74..1b23b86a 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -1400,10 +1400,7 @@ mod upload_bundle { hash: bundles::Hash(hash.into()), kind, }; let mut progress = termprogress::new(); - chan.cmd_withbulk(&cmd, &mut f, &mut io::sink(), &mut |pi|{ - progress.report(&pi); - Ok(()) - })?; + chan.cmd_withbulk(&cmd, &mut f, &mut io::sink(), &mut *progress)?; } inventory::submit!{Subcommand( @@ -1506,7 +1503,8 @@ mod download_bundle { game: instance_name.clone(), id, }; - chan.cmd_withbulk(&cmd, &mut io::empty(), &mut f, &mut |_| Ok(())) + chan.cmd_withbulk(&cmd, &mut io::empty(), &mut f, + &mut termprogress::NullReporter) .context("download bundle")?; f.flush().context("flush bundle file")?; if let Some((path, tmp)) = path_tmp { diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index bd14e7e4..41583e20 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -69,11 +69,11 @@ impl MgmtChannel { } #[throws(AE)] - pub fn cmd_withbulk(&mut self, cmd: &MgmtCommand, - up: &mut U, down: &mut D, progress: &mut P) - -> MgmtResponse + pub fn cmd_withbulk(&mut self, cmd: &MgmtCommand, + up: &mut U, down: &mut D, + progress: &mut dyn termprogress::Reporter) + -> MgmtResponse where U: Read, D: Write, - P: FnMut(ProgressInfo) -> Result<(),AE>, { use MgmtResponse::*; let mut wbulk = self.write @@ -86,7 +86,7 @@ impl MgmtChannel { .context("read response")?; while let MR::Progress(pi) = resp { resp = (&mut rbulk).read_rmp()?; - progress(pi)?; + progress.report(&pi); } match &resp { Progress(_) => panic!(), @@ -119,7 +119,8 @@ impl MgmtChannel { #[throws(AE)] pub fn cmd(&mut self, cmd: &MgmtCommand) -> MgmtResponse { - self.cmd_withbulk(cmd, &mut io::empty(), &mut io::sink(), &mut |_|Ok(()))? + self.cmd_withbulk(cmd, &mut io::empty(), &mut io::sink(), + &mut termprogress::NullReporter)? } pub fn read_inner_mut(&mut self) -> &mut TimedFdReader { -- 2.30.2