From 261d2aac48b3a1bdd68ef52d9d412161e55e833d Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Wed, 27 Jul 2016 23:54:49 -0700 Subject: [PATCH] Remove `Ticker` alias The `Counter` NewType can fill this role. --- examples/progress.rs | 12 ++++++------ src/view/mod.rs | 2 +- src/view/progress_bar.rs | 18 +++++------------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/examples/progress.rs b/examples/progress.rs index efa4787..62591c1 100644 --- a/examples/progress.rs +++ b/examples/progress.rs @@ -4,7 +4,7 @@ extern crate rand; use rand::Rng; use cursive::prelude::*; -use cursive::view::{Counter, Ticker}; +use cursive::view::Counter; use std::thread; use std::cmp::min; @@ -26,11 +26,11 @@ fn main() { } // Function to simulate a long process. -fn fake_load(n_max: usize, ticker: Ticker) { +fn fake_load(n_max: usize, counter: Counter) { for _ in 0..n_max { thread::sleep(Duration::from_millis(5)); - // The ticker method increases the progress value - ticker(1); + // The `counter.tick()` method increases the progress value + counter.tick(1); } } @@ -46,9 +46,9 @@ fn phase_1(s: &mut Cursive) { s.pop_layer(); s.add_layer(Panel::new(FullView::full_width(ProgressBar::new() .range(0, n_max) - .with_task(move |ticker| { + .with_task(move |counter| { // This closure will be called in a separate thread. - fake_load(n_max, ticker); + fake_load(n_max, counter); // When we're done, send a callback through the channel cb.send(Box::new(coffee_break)).unwrap(); diff --git a/src/view/mod.rs b/src/view/mod.rs index f050c1a..694f02a 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -94,7 +94,7 @@ pub use self::menubar::Menubar; pub use self::menu_popup::MenuPopup; pub use self::view_path::ViewPath; pub use self::panel::Panel; -pub use self::progress_bar::{Counter, ProgressBar, Ticker}; +pub use self::progress_bar::{Counter, ProgressBar}; pub use self::select_view::SelectView; pub use self::shadow_view::ShadowView; pub use self::sized_view::SizedView; diff --git a/src/view/progress_bar.rs b/src/view/progress_bar.rs index c814df9..cbc35d6 100644 --- a/src/view/progress_bar.rs +++ b/src/view/progress_bar.rs @@ -68,11 +68,6 @@ pub struct ProgressBar { label_maker: Box String>, } -/// Function used by tasks given to a `ProgressBar`. -/// -/// This function will increment the progress bar counter by the given value. -pub type Ticker = Box; - fn make_percentage(value: usize, (min, max): (usize, usize)) -> String { if value < min { @@ -115,15 +110,12 @@ impl ProgressBar { /// Starts a function in a separate thread, and monitor the progress. /// - /// `f` will be given a `Ticker` to increment the bar's progress. + /// `f` will be given a `Counter` to increment the bar's progress. /// /// This does not reset the value, so it can be called several times /// to advance the progress in multiple sessions. - pub fn start(&mut self, f: F) { - let value = self.value.clone(); - let ticker: Ticker = Box::new(move |ticks| { - value.tick(ticks); - }); + pub fn start(&mut self, f: F) { + let ticker: Counter = self.value.clone(); thread::spawn(move || { f(ticker); @@ -133,8 +125,8 @@ impl ProgressBar { /// Starts a function in a separate thread, and monitor the progress. /// /// Chainable variant. - pub fn with_task(mut self, task: F) - -> Self { + pub fn with_task(mut self, task: F) + -> Self { self.start(task); self }