chiark / gitweb /
progress: Make cmd_withbulk take termprogress::Reporter, not a Fn
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 17 May 2021 10:54:28 +0000 (11:54 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 17 May 2021 13:58:58 +0000 (14:58 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/otter.rs
src/mgmtchannel.rs

index dcac0d74cf085c3edcf0b2dadf09d33690981cae..1b23b86aefb37fa22950d068029f2c83dbde12b1 100644 (file)
@@ -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 {
index bd14e7e45503ce43e1611d04f41375c68333a145..41583e202ab69b8b64368427222707de1925bdf4 100644 (file)
@@ -69,11 +69,11 @@ impl MgmtChannel {
   }
 
   #[throws(AE)]
-  pub fn cmd_withbulk<U,D,P>(&mut self, cmd: &MgmtCommand,
-                             up: &mut U, down: &mut D, progress: &mut P)
-                             -> MgmtResponse
+  pub fn cmd_withbulk<U,D>(&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 {