warning: unused variable: `phase`
--> src/progress.rs:53:40
|
53 | fn phase_entry<'p,'e,P,E>(&mut self, phase: P, entry: E)
| ^^^^^ help: if this is intentional, prefix it with an underscore: `_phase`
|
= note: `#[warn(unused_variables)]` on by default
rustc 1.53.0-nightly (
132b4e5d1 2021-04-13)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
#[throws(EH::Err)]
fn parse_bundle<EH>(id: Id, file: &mut dyn ReadSeek, eh: EH,
- _for_progress: &mut dyn ProgressReporter) -> Parsed
+ _for_progress: &mut dyn progress::Reporter) -> Parsed
where EH: BundleParseErrorHandling,
{
match id.kind { Kind::Zip => () }
#[throws(LE)]
fn process_bundle(id: Id, instance: &InstanceName,
- _for_progress: &dyn ProgressReporter)
+ _for_progress: &dyn progress::Reporter)
{
let dir = id.path_dir(instance);
fs::create_dir(&dir)
impl Uploading {
#[throws(MgmtError)]
pub fn bulk<R>(self, data: &mut R, expected: &Hash,
- for_progress: &mut dyn ProgressReporter) -> Uploaded
+ for_progress: &mut dyn progress::Reporter) -> Uploaded
where R: Read
{
let Uploading { id, mut file, instance } = self;
pub use serde_with::SerializeDisplay;
pub use sha2::{Sha512, Sha512Trunc256};
pub use slotmap::{dense::DenseSlotMap, SparseSecondaryMap, Key as _};
-pub use strum::{EnumString, EnumIter, EnumProperty};
+pub use strum::{AsStaticRef, EnumCount, EnumString, EnumIter, EnumProperty};
pub use strum::{IntoEnumIterator, IntoStaticStr};
pub use subtle::ConstantTimeEq;
pub use tempfile::NamedTempFile;
pub use crate::pcaliases::*;
pub use crate::pcrender::*;
pub use crate::pieces::*;
-pub use crate::progress::*;
+pub use crate::progress::{self, ProgressInfo};
pub use crate::shapelib;
pub use crate::shapelib::{CircleShape, RectShape};
pub use crate::slotmap_slot_idx::*;
#[derive(Debug,Clone,Serialize,Deserialize,IntoOwned)]
pub struct ProgressInfo<'pi> {
- phase_num: usize,
- phases: usize,
- phase_desc: Cow<'pi, str>,
- count: usize,
- of: usize,
- desc: Cow<'pi, str>,
+ phase: Count<'pi>,
+ entry: Count<'pi>,
}
-pub trait ProgressReporter {
+#[derive(Debug,Clone,Serialize,Deserialize,IntoOwned)]
+pub struct Count<'pi> {
+ pub i: usize,
+ pub n: usize,
+ pub desc: Cow<'pi, str>,
+}
+
+pub trait Reporter {
fn report(&mut self, info: ProgressInfo<'_>)
-> Result<(), MgmtChannelWriteError>;
}
-impl<W> ProgressReporter for ResponseWriter<'_, W> where W: Write {
+impl<W> Reporter for ResponseWriter<'_, W> where W: Write {
#[throws(MgmtChannelWriteError)]
fn report(&mut self, pi: ProgressInfo<'_>) {
self.progress(pi)?
}
}
-impl ProgressReporter for () {
+impl Reporter for () {
#[throws(MgmtChannelWriteError)]
fn report(&mut self, _pi: ProgressInfo<'_>) { }
}
+
+impl<T> From<T> for Count<'static>
+where T: EnumCount + ToPrimitive + AsStaticRef<str>
+{
+ fn from(t: T) -> Count<'static> {
+ Count {
+ i: t.to_usize().unwrap(),
+ n: T::COUNT,
+ desc: Cow::Borrowed(t.as_static()),
+ }
+ }
+}
+
+#[ext(pub)]
+impl &mut dyn Reporter {
+ #[throws(MgmtChannelWriteError)]
+ fn phase_entry<'p,'e,P,E>(&mut self, phase: P, entry: E)
+ where P: Into<Count<'p>>,
+ E: Into<Count<'e>>,
+ {
+ self.report(ProgressInfo {
+ phase: phase.into(),
+ entry: entry.into(),
+ })?
+ }
+}