diff --git a/examples/multi-tree-ext.rs b/examples/multi-tree-ext.rs index 3401c5d6..e0d85d8d 100644 --- a/examples/multi-tree-ext.rs +++ b/examples/multi-tree-ext.rs @@ -1,12 +1,14 @@ -use console::style; -use indicatif::{MultiProgress, MultiProgressAlignment, ProgressBar, ProgressStyle}; -use once_cell::sync::Lazy; -use rand::{rngs::ThreadRng, Rng, RngCore}; use std::fmt::Debug; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use std::thread; use std::time::Duration; + +use console::style; +use indicatif::{MultiProgress, MultiProgressAlignment, ProgressBar, ProgressStyle}; +use once_cell::sync::Lazy; +use rand::rngs::ThreadRng; +use rand::{Rng, RngCore}; use structopt::StructOpt; #[derive(Debug, Clone)] diff --git a/examples/multi-tree.rs b/examples/multi-tree.rs index 2dd05633..785ccae7 100644 --- a/examples/multi-tree.rs +++ b/examples/multi-tree.rs @@ -1,11 +1,13 @@ -use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; -use once_cell::sync::Lazy; -use rand::{rngs::ThreadRng, Rng, RngCore}; use std::fmt::Debug; use std::sync::{Arc, Mutex}; use std::thread; use std::time::Duration; +use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; +use once_cell::sync::Lazy; +use rand::rngs::ThreadRng; +use rand::{Rng, RngCore}; + #[derive(Debug, Clone)] enum Action { AddProgressBar(usize), diff --git a/examples/tokio.rs b/examples/tokio.rs index 313ac57f..17ac2b1f 100644 --- a/examples/tokio.rs +++ b/examples/tokio.rs @@ -1,5 +1,6 @@ -use indicatif::ProgressBar; use std::time::Duration; + +use indicatif::ProgressBar; use tokio::runtime; use tokio::time::interval; diff --git a/examples/yarnish.rs b/examples/yarnish.rs index 804c1cec..1cfdf70e 100644 --- a/examples/yarnish.rs +++ b/examples/yarnish.rs @@ -1,10 +1,10 @@ -use rand::seq::SliceRandom; -use rand::Rng; use std::thread; use std::time::{Duration, Instant}; use console::{style, Emoji}; use indicatif::{HumanDuration, MultiProgress, ProgressBar, ProgressStyle}; +use rand::seq::SliceRandom; +use rand::Rng; static PACKAGES: &[&str] = &[ "fs-events", diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..3a3f3f1d --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,2 @@ +imports_granularity = "Module" +group_imports = "StdExternalCrate" diff --git a/src/lib.rs b/src/lib.rs index c147f306..eadeaf68 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -237,9 +237,8 @@ pub use crate::in_memory::InMemoryTerm; pub use crate::iter::{ProgressBarIter, ProgressIterator}; pub use crate::multi::{MultiProgress, MultiProgressAlignment}; pub use crate::progress_bar::{ProgressBar, WeakProgressBar}; +#[cfg(feature = "rayon")] +pub use crate::rayon::ParallelProgressIterator; pub use crate::state::{ProgressFinish, ProgressState}; pub use crate::style::ProgressStyle; pub use crate::term_like::TermLike; - -#[cfg(feature = "rayon")] -pub use crate::rayon::ParallelProgressIterator; diff --git a/src/progress_bar.rs b/src/progress_bar.rs index fc15e11f..01e37134 100644 --- a/src/progress_bar.rs +++ b/src/progress_bar.rs @@ -1,20 +1,17 @@ use std::borrow::Cow; -use std::sync::{Arc, Mutex, Weak}; -use std::sync::{Condvar, MutexGuard}; +#[cfg(test)] +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, Condvar, Mutex, MutexGuard, Weak}; use std::time::{Duration, Instant}; -use std::{fmt, mem}; -use std::{io, thread}; +use std::{fmt, io, mem, thread}; #[cfg(test)] use once_cell::sync::Lazy; -#[cfg(test)] -use std::sync::atomic::{AtomicBool, Ordering}; use crate::draw_target::ProgressDrawTarget; use crate::state::{AtomicPosition, BarState, ProgressFinish, Reset}; use crate::style::ProgressStyle; -use crate::ProgressState; -use crate::{ProgressBarIter, ProgressIterator}; +use crate::{ProgressBarIter, ProgressIterator, ProgressState}; /// A progress bar or spinner /// @@ -605,7 +602,8 @@ impl TickerControl { // Wait for `interval` but return early if we are notified to stop let (_, result) = self - .stopping.1 + .stopping + .1 .wait_timeout_while(self.stopping.0.lock().unwrap(), interval, |stopped| { !*stopped }) diff --git a/src/rayon.rs b/src/rayon.rs index 73722a2e..fc66d7af 100644 --- a/src/rayon.rs +++ b/src/rayon.rs @@ -1,10 +1,10 @@ -use crate::{ProgressBar, ProgressBarIter}; -use rayon::iter::{ - plumbing::{Consumer, Folder, Producer, ProducerCallback, UnindexedConsumer}, - IndexedParallelIterator, ParallelIterator, -}; use std::convert::TryFrom; +use rayon::iter::plumbing::{Consumer, Folder, Producer, ProducerCallback, UnindexedConsumer}; +use rayon::iter::{IndexedParallelIterator, ParallelIterator}; + +use crate::{ProgressBar, ProgressBarIter}; + /// Wraps a Rayon parallel iterator. /// /// See [`ProgressIterator`](trait.ProgressIterator.html) for method @@ -210,10 +210,10 @@ impl> ParallelIterator for ProgressBarIte #[cfg(test)] mod test { - use crate::ProgressStyle; - use crate::{ParallelProgressIterator, ProgressBar, ProgressBarIter}; use rayon::iter::{IntoParallelRefIterator, ParallelIterator}; + use crate::{ParallelProgressIterator, ProgressBar, ProgressBarIter, ProgressStyle}; + #[test] fn it_can_wrap_a_parallel_iterator() { let v = vec![1, 2, 3]; diff --git a/src/state.rs b/src/state.rs index 6ee2c1ef..6f5e9c46 100644 --- a/src/state.rs +++ b/src/state.rs @@ -1,9 +1,8 @@ use std::borrow::Cow; -use std::fmt; -use std::io; use std::sync::atomic::{AtomicU64, AtomicU8, Ordering}; use std::sync::Arc; use std::time::{Duration, Instant}; +use std::{fmt, io}; use crate::draw_target::ProgressDrawTarget; use crate::style::ProgressStyle; @@ -484,9 +483,8 @@ pub(crate) enum Status { #[cfg(test)] mod tests { - use crate::ProgressBar; - use super::*; + use crate::ProgressBar; #[test] fn test_time_per_step() { diff --git a/src/style.rs b/src/style.rs index 01ad2fc7..ec0768d1 100644 --- a/src/style.rs +++ b/src/style.rs @@ -676,9 +676,10 @@ enum Alignment { #[cfg(test)] mod tests { + use std::sync::Arc; + use super::*; use crate::state::{AtomicPosition, ProgressState}; - use std::sync::Arc; #[test] fn test_expand_template() { diff --git a/src/term_like.rs b/src/term_like.rs index a0be7d71..ecda634a 100644 --- a/src/term_like.rs +++ b/src/term_like.rs @@ -1,7 +1,8 @@ -use console::Term; use std::fmt::Debug; use std::io; +use console::Term; + /// A trait for minimal terminal-like behavior. /// /// Anything that implements this trait can be used a draw target via [`ProgressDrawTarget::term_like`]. diff --git a/tests/multi-autodrop.rs b/tests/multi-autodrop.rs index 6e9a7c85..24457a61 100644 --- a/tests/multi-autodrop.rs +++ b/tests/multi-autodrop.rs @@ -1,7 +1,8 @@ -use indicatif::{MultiProgress, ProgressBar}; use std::thread; use std::time::Duration; +use indicatif::{MultiProgress, ProgressBar}; + #[test] fn main() { let pb = { diff --git a/tests/render.rs b/tests/render.rs index c2d5399f..c0da931b 100644 --- a/tests/render.rs +++ b/tests/render.rs @@ -1,10 +1,11 @@ #![cfg(feature = "in_memory")] +use std::time::Duration; + use indicatif::{ InMemoryTerm, MultiProgress, ProgressBar, ProgressDrawTarget, ProgressFinish, ProgressStyle, TermLike, }; -use std::time::Duration; #[test] fn basic_progress_bar() {