diff options
Diffstat (limited to 'vendor/prodash/src')
-rw-r--r-- | vendor/prodash/src/lib.rs | 2 | ||||
-rw-r--r-- | vendor/prodash/src/progress/key.rs | 9 | ||||
-rw-r--r-- | vendor/prodash/src/progress/log.rs | 2 | ||||
-rw-r--r-- | vendor/prodash/src/progress/mod.rs | 9 | ||||
-rw-r--r-- | vendor/prodash/src/progress/utils.rs | 8 | ||||
-rw-r--r-- | vendor/prodash/src/render/line/draw.rs | 8 | ||||
-rw-r--r-- | vendor/prodash/src/traits.rs | 260 | ||||
-rw-r--r-- | vendor/prodash/src/tree/item.rs | 4 |
8 files changed, 252 insertions, 50 deletions
diff --git a/vendor/prodash/src/lib.rs b/vendor/prodash/src/lib.rs index 974cc8598..e3eb6042c 100644 --- a/vendor/prodash/src/lib.rs +++ b/vendor/prodash/src/lib.rs @@ -64,7 +64,7 @@ pub mod messages; pub mod progress; mod traits; -pub use traits::{Progress, Root, WeakRoot}; +pub use traits::{Progress, RawProgress, Root, WeakRoot}; mod throughput; pub use crate::throughput::Throughput; diff --git a/vendor/prodash/src/progress/key.rs b/vendor/prodash/src/progress/key.rs index dae714d68..bfdf13b2d 100644 --- a/vendor/prodash/src/progress/key.rs +++ b/vendor/prodash/src/progress/key.rs @@ -15,12 +15,13 @@ pub(crate) type Id = u16; pub struct Key(Option<Id>, Option<Id>, Option<Id>, Option<Id>, Option<Id>, Option<Id>); /// Determines if a sibling is above or below in the given level of hierarchy -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] +#[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)] #[allow(missing_docs)] pub enum SiblingLocation { Above, Below, AboveAndBelow, + #[default] NotFound, } @@ -40,12 +41,6 @@ impl SiblingLocation { } } -impl Default for SiblingLocation { - fn default() -> Self { - SiblingLocation::NotFound - } -} - /// A type providing information about what's above and below `Tree` items. #[derive(Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd, Debug)] pub struct Adjacency( diff --git a/vendor/prodash/src/progress/log.rs b/vendor/prodash/src/progress/log.rs index 3410a5dc2..6fb16f109 100644 --- a/vendor/prodash/src/progress/log.rs +++ b/vendor/prodash/src/progress/log.rs @@ -136,7 +136,7 @@ impl Progress for Log { self.id } - fn message(&mut self, level: MessageLevel, message: impl Into<String>) { + fn message(&self, level: MessageLevel, message: impl Into<String>) { let message: String = message.into(); match level { MessageLevel::Info => log::info!("ℹ{} → {}", self.name, message), diff --git a/vendor/prodash/src/progress/mod.rs b/vendor/prodash/src/progress/mod.rs index 0d9c694cf..842bbb6e1 100644 --- a/vendor/prodash/src/progress/mod.rs +++ b/vendor/prodash/src/progress/mod.rs @@ -41,7 +41,7 @@ pub type Step = usize; pub type StepShared = Arc<AtomicUsize>; /// Indicate whether a progress can or cannot be made. -#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)] +#[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash)] pub enum State { /// Indicates a task is blocked and cannot indicate progress, optionally until the /// given time. The task cannot easily be interrupted. @@ -50,15 +50,10 @@ pub enum State { /// given time. The task can be interrupted. Halted(&'static str, Option<SystemTime>), /// The task is running + #[default] Running, } -impl Default for State { - fn default() -> Self { - State::Running - } -} - /// Progress associated with some item in the progress tree. #[derive(Clone, Default, Debug)] pub struct Value { diff --git a/vendor/prodash/src/progress/utils.rs b/vendor/prodash/src/progress/utils.rs index 549a0b6e5..3fd6c64bf 100644 --- a/vendor/prodash/src/progress/utils.rs +++ b/vendor/prodash/src/progress/utils.rs @@ -38,7 +38,7 @@ impl Progress for Discard { crate::progress::UNKNOWN } - fn message(&mut self, _level: MessageLevel, _message: impl Into<String>) {} + fn message(&self, _level: MessageLevel, _message: impl Into<String>) {} fn counter(&self) -> Option<StepShared> { None @@ -144,7 +144,7 @@ where todo!() } - fn message(&mut self, level: MessageLevel, message: impl Into<String>) { + fn message(&self, level: MessageLevel, message: impl Into<String>) { match self { Either::Left(l) => l.message(level, message), Either::Right(r) => r.message(level, message), @@ -247,7 +247,7 @@ where self.0.id() } - fn message(&mut self, level: MessageLevel, message: impl Into<String>) { + fn message(&self, level: MessageLevel, message: impl Into<String>) { self.0.message(level, message) } @@ -321,7 +321,7 @@ impl<T: Progress> Progress for ThroughputOnDrop<T> { self.0.id() } - fn message(&mut self, level: MessageLevel, message: impl Into<String>) { + fn message(&self, level: MessageLevel, message: impl Into<String>) { self.0.message(level, message) } diff --git a/vendor/prodash/src/render/line/draw.rs b/vendor/prodash/src/render/line/draw.rs index b45badf11..85dc18eb9 100644 --- a/vendor/prodash/src/render/line/draw.rs +++ b/vendor/prodash/src/render/line/draw.rs @@ -230,13 +230,7 @@ fn block_count_sans_ansi_codes(strings: &[ANSIString<'_>]) -> u16 { strings.iter().map(|s| s.width() as u16).sum() } -fn draw_progress_bar<'a>( - p: &Value, - style: Style, - mut blocks_available: u16, - colored: bool, - buf: &mut Vec<ANSIString<'a>>, -) { +fn draw_progress_bar(p: &Value, style: Style, mut blocks_available: u16, colored: bool, buf: &mut Vec<ANSIString<'_>>) { let mut brush = color::Brush::new(colored); let styled_brush = brush.style(style); diff --git a/vendor/prodash/src/traits.rs b/vendor/prodash/src/traits.rs index a2a17c760..1aac1d43a 100644 --- a/vendor/prodash/src/traits.rs +++ b/vendor/prodash/src/traits.rs @@ -2,8 +2,8 @@ use std::time::Instant; use crate::{messages::MessageLevel, progress, progress::Id, Unit}; -/// A trait for describing hierarchical process. -pub trait Progress: Send { +/// A trait for describing hierarchical progress. +pub trait Progress: Send + Sync { /// The type of progress returned by [`add_child()`][Progress::add_child()]. type SubProgress: Progress; @@ -87,7 +87,7 @@ pub trait Progress: Send { /// /// Use this to provide additional,human-readable information about the progress /// made, including indicating success or failure. - fn message(&mut self, level: MessageLevel, message: impl Into<String>); + fn message(&self, level: MessageLevel, message: impl Into<String>); /// If available, return an atomic counter for direct access to the underlying state. /// @@ -98,19 +98,19 @@ pub trait Progress: Send { } /// Create a message providing additional information about the progress thus far. - fn info(&mut self, message: impl Into<String>) { + fn info(&self, message: impl Into<String>) { self.message(MessageLevel::Info, message) } /// Create a message indicating the task is done successfully - fn done(&mut self, message: impl Into<String>) { + fn done(&self, message: impl Into<String>) { self.message(MessageLevel::Success, message) } /// Create a message indicating the task failed - fn fail(&mut self, message: impl Into<String>) { + fn fail(&self, message: impl Into<String>) { self.message(MessageLevel::Failure, message) } /// A shorthand to print throughput information - fn show_throughput(&mut self, start: Instant) { + fn show_throughput(&self, start: Instant) { let step = self.step(); match self.unit() { Some(unit) => self.show_throughput_with(start, step, unit, MessageLevel::Info), @@ -126,7 +126,147 @@ pub trait Progress: Send { } /// A shorthand to print throughput information, with the given step and unit, and message level. - fn show_throughput_with(&mut self, start: Instant, step: progress::Step, unit: Unit, level: MessageLevel) { + fn show_throughput_with(&self, start: Instant, step: progress::Step, unit: Unit, level: MessageLevel) { + use std::fmt::Write; + let elapsed = start.elapsed().as_secs_f32(); + let steps_per_second = (step as f32 / elapsed) as progress::Step; + let mut buf = String::with_capacity(128); + let unit = unit.as_display_value(); + let push_unit = |buf: &mut String| { + buf.push(' '); + let len_before_unit = buf.len(); + unit.display_unit(buf, step).ok(); + if buf.len() == len_before_unit { + buf.pop(); + } + }; + + buf.push_str("done "); + unit.display_current_value(&mut buf, step, None).ok(); + push_unit(&mut buf); + + buf.write_fmt(format_args!(" in {:.02}s (", elapsed)).ok(); + unit.display_current_value(&mut buf, steps_per_second, None).ok(); + push_unit(&mut buf); + buf.push_str("/s)"); + + self.message(level, buf); + } +} + +/// A trait for describing non-hierarchical progress. +/// +/// It differs by not being able to add child progress dynamically, but in turn is object safe. It's recommended to +/// use this trait whenever there is no need to add child progress, at the leaf of a computation. +// NOTE: keep this in-sync with `Progress`. +pub trait RawProgress: Send + Sync { + /// Initialize the Item for receiving progress information. + /// + /// If `max` is `Some(…)`, it will be treated as upper bound. When progress is [set(…)](./struct.Item.html#method.set) + /// it should not exceed the given maximum. + /// If `max` is `None`, the progress is unbounded. Use this if the amount of work cannot accurately + /// be determined in advance. + /// + /// If `unit` is `Some(…)`, it is used for display purposes only. See `prodash::Unit` for more information. + /// + /// If both `unit` and `max` are `None`, the item will be reset to be equivalent to 'uninitialized'. + /// + /// If this method is never called, this `Progress` instance will serve as organizational unit, useful to add more structure + /// to the progress tree (e.g. a headline). + /// + /// **Note** that this method can be called multiple times, changing the bounded-ness and unit at will. + fn init(&mut self, max: Option<progress::Step>, unit: Option<Unit>); + + /// Set the current progress to the given `step`. The cost of this call is negligible, + /// making manual throttling *not* necessary. + /// + /// **Note**: that this call has no effect unless `init(…)` was called before. + fn set(&mut self, step: progress::Step); + + /// Returns the (cloned) unit associated with this Progress + fn unit(&self) -> Option<Unit> { + None + } + + /// Returns the maximum about of items we expect, as provided with the `init(…)` call + fn max(&self) -> Option<progress::Step> { + None + } + + /// Set the maximum value to `max` and return the old maximum value. + fn set_max(&mut self, _max: Option<progress::Step>) -> Option<progress::Step> { + None + } + + /// Returns the current step, as controlled by `inc*(…)` calls + fn step(&self) -> progress::Step; + + /// Increment the current progress to the given `step`. + /// The cost of this call is negligible, making manual throttling *not* necessary. + fn inc_by(&mut self, step: progress::Step); + + /// Increment the current progress to the given 1. The cost of this call is negligible, + /// making manual throttling *not* necessary. + fn inc(&mut self) { + self.inc_by(1) + } + + /// Set the name of the instance, altering the value given when crating it with `add_child(…)` + /// The progress is allowed to discard it. + fn set_name(&mut self, name: String); + + /// Get the name of the instance as given when creating it with `add_child(…)` + /// The progress is allowed to not be named, thus there is no guarantee that a previously set names 'sticks'. + fn name(&self) -> Option<String>; + + /// Get a stable identifier for the progress instance. + /// Note that it could be [unknown][crate::progress::UNKNOWN]. + fn id(&self) -> Id; + + /// Create a `message` of the given `level` and store it with the progress tree. + /// + /// Use this to provide additional,human-readable information about the progress + /// made, including indicating success or failure. + fn message(&self, level: MessageLevel, message: String); + + /// If available, return an atomic counter for direct access to the underlying state. + /// + /// This is useful if multiple threads want to access the same progress, without the need + /// for provide each their own progress and aggregating the result. + fn counter(&self) -> Option<StepShared> { + None + } + + /// Create a message providing additional information about the progress thus far. + fn info(&self, message: String) { + self.message(MessageLevel::Info, message) + } + /// Create a message indicating the task is done successfully + fn done(&self, message: String) { + self.message(MessageLevel::Success, message) + } + /// Create a message indicating the task failed + fn fail(&self, message: String) { + self.message(MessageLevel::Failure, message) + } + /// A shorthand to print throughput information + fn show_throughput(&self, start: Instant) { + let step = self.step(); + match self.unit() { + Some(unit) => self.show_throughput_with(start, step, unit, MessageLevel::Info), + None => { + let elapsed = start.elapsed().as_secs_f32(); + let steps_per_second = (step as f32 / elapsed) as progress::Step; + self.info(format!( + "done {} items in {:.02}s ({} items/s)", + step, elapsed, steps_per_second + )) + } + }; + } + + /// A shorthand to print throughput information, with the given step and unit, and message level. + fn show_throughput_with(&self, start: Instant, step: progress::Step, unit: Unit, level: MessageLevel) { use std::fmt::Write; let elapsed = start.elapsed().as_secs_f32(); let steps_per_second = (step as f32 / elapsed) as progress::Step; @@ -205,12 +345,90 @@ mod impls { time::Instant, }; + use crate::traits::RawProgress; use crate::{ messages::MessageLevel, progress::{Id, Step, StepShared}, Progress, Unit, }; + impl<T> RawProgress for T + where + T: Progress, + { + fn init(&mut self, max: Option<Step>, unit: Option<Unit>) { + <T as Progress>::init(self, max, unit) + } + + fn set(&mut self, step: Step) { + <T as Progress>::set(self, step) + } + + fn unit(&self) -> Option<Unit> { + <T as Progress>::unit(self) + } + + fn max(&self) -> Option<Step> { + <T as Progress>::max(self) + } + + fn set_max(&mut self, max: Option<Step>) -> Option<Step> { + <T as Progress>::set_max(self, max) + } + + fn step(&self) -> Step { + <T as Progress>::step(self) + } + + fn inc_by(&mut self, step: Step) { + <T as Progress>::inc_by(self, step) + } + + fn inc(&mut self) { + <T as Progress>::inc(self) + } + + fn set_name(&mut self, name: String) { + <T as Progress>::set_name(self, name) + } + + fn name(&self) -> Option<String> { + <T as Progress>::name(self) + } + + fn id(&self) -> Id { + <T as Progress>::id(self) + } + + fn message(&self, level: MessageLevel, message: String) { + <T as Progress>::message(self, level, message) + } + + fn counter(&self) -> Option<StepShared> { + <T as Progress>::counter(self) + } + + fn info(&self, message: String) { + <T as Progress>::info(self, message) + } + + fn done(&self, message: String) { + <T as Progress>::done(self, message) + } + + fn fail(&self, message: String) { + <T as Progress>::fail(self, message) + } + + fn show_throughput(&self, start: Instant) { + <T as Progress>::show_throughput(self, start) + } + + fn show_throughput_with(&self, start: Instant, step: Step, unit: Unit, level: MessageLevel) { + <T as Progress>::show_throughput_with(self, start, step, unit, level) + } + } + impl<'a, T> Progress for &'a mut T where T: Progress, @@ -266,35 +484,35 @@ mod impls { } fn id(&self) -> Id { - todo!() + self.deref().id() } - fn message(&mut self, level: MessageLevel, message: impl Into<String>) { - self.deref_mut().message(level, message) + fn message(&self, level: MessageLevel, message: impl Into<String>) { + self.deref().message(level, message) } fn counter(&self) -> Option<StepShared> { self.deref().counter() } - fn info(&mut self, message: impl Into<String>) { - self.deref_mut().info(message) + fn info(&self, message: impl Into<String>) { + self.deref().info(message) } - fn done(&mut self, message: impl Into<String>) { - self.deref_mut().done(message) + fn done(&self, message: impl Into<String>) { + self.deref().done(message) } - fn fail(&mut self, message: impl Into<String>) { - self.deref_mut().fail(message) + fn fail(&self, message: impl Into<String>) { + self.deref().fail(message) } - fn show_throughput(&mut self, start: Instant) { - self.deref_mut().show_throughput(start) + fn show_throughput(&self, start: Instant) { + self.deref().show_throughput(start) } - fn show_throughput_with(&mut self, start: Instant, step: Step, unit: Unit, level: MessageLevel) { - self.deref_mut().show_throughput_with(start, step, unit, level) + fn show_throughput_with(&self, start: Instant, step: Step, unit: Unit, level: MessageLevel) { + self.deref().show_throughput_with(start, step, unit, level) } } } diff --git a/vendor/prodash/src/tree/item.rs b/vendor/prodash/src/tree/item.rs index d8c4a7548..17dbb64da 100644 --- a/vendor/prodash/src/tree/item.rs +++ b/vendor/prodash/src/tree/item.rs @@ -292,7 +292,7 @@ impl Item { /// /// Use this to provide additional,human-readable information about the progress /// made, including indicating success or failure. - pub fn message(&mut self, level: MessageLevel, message: impl Into<String>) { + pub fn message(&self, level: MessageLevel, message: impl Into<String>) { let message: String = message.into(); self.messages.lock().push_overwrite( level, @@ -396,7 +396,7 @@ impl crate::Progress for Item { Item::id(self) } - fn message(&mut self, level: MessageLevel, message: impl Into<String>) { + fn message(&self, level: MessageLevel, message: impl Into<String>) { Item::message(self, level, message) } |