diff --git a/examples/multi-tree-ext.rs b/examples/multi-tree-ext.rs index e0d85d8d..c647cbfe 100644 --- a/examples/multi-tree-ext.rs +++ b/examples/multi-tree-ext.rs @@ -255,7 +255,7 @@ pub fn main() { } /// The function guarantees to return the action, that is valid for the current tree. -fn get_action<'a>(rng: &'a mut dyn RngCore, items: &[&Item]) -> Action { +fn get_action(rng: &mut dyn RngCore, items: &[&Item]) -> Action { let elem_idx = ELEM_IDX.load(Ordering::SeqCst); // the indices of those items, that not completed yet let uncompleted = items diff --git a/examples/multi-tree.rs b/examples/multi-tree.rs index 785ccae7..63540f97 100644 --- a/examples/multi-tree.rs +++ b/examples/multi-tree.rs @@ -150,7 +150,7 @@ fn main() { } /// The function guarantees to return the action, that is valid for the current tree. -fn get_action<'a>(rng: &'a mut dyn RngCore, tree: &Mutex>) -> Option { +fn get_action(rng: &mut dyn RngCore, tree: &Mutex>) -> Option { let elem_len = ELEMENTS.len() as u64; let list_len = tree.lock().unwrap().len() as u64; let sum_free = tree diff --git a/src/draw_target.rs b/src/draw_target.rs index ba363d89..41d513d5 100644 --- a/src/draw_target.rs +++ b/src/draw_target.rs @@ -23,30 +23,30 @@ impl ProgressDrawTarget { /// Draw to a buffered stdout terminal at a max of 20 times a second. /// /// For more information see `ProgressDrawTarget::to_term`. - pub fn stdout() -> ProgressDrawTarget { - ProgressDrawTarget::term(Term::buffered_stdout(), 20) + pub fn stdout() -> Self { + Self::term(Term::buffered_stdout(), 20) } /// Draw to a buffered stderr terminal at a max of 20 times a second. /// /// This is the default draw target for progress bars. For more /// information see `ProgressDrawTarget::to_term`. - pub fn stderr() -> ProgressDrawTarget { - ProgressDrawTarget::term(Term::buffered_stderr(), 20) + pub fn stderr() -> Self { + Self::term(Term::buffered_stderr(), 20) } /// Draw to a buffered stdout terminal at a max of `refresh_rate` times a second. /// /// For more information see `ProgressDrawTarget::to_term`. - pub fn stdout_with_hz(refresh_rate: u8) -> ProgressDrawTarget { - ProgressDrawTarget::term(Term::buffered_stdout(), refresh_rate) + pub fn stdout_with_hz(refresh_rate: u8) -> Self { + Self::term(Term::buffered_stdout(), refresh_rate) } /// Draw to a buffered stderr terminal at a max of `refresh_rate` times a second. /// /// For more information see `ProgressDrawTarget::to_term`. - pub fn stderr_with_hz(refresh_rate: u8) -> ProgressDrawTarget { - ProgressDrawTarget::term(Term::buffered_stderr(), refresh_rate) + pub fn stderr_with_hz(refresh_rate: u8) -> Self { + Self::term(Term::buffered_stderr(), refresh_rate) } pub(crate) fn new_remote(state: Arc>, idx: usize) -> Self { @@ -63,8 +63,8 @@ impl ProgressDrawTarget { /// useless escape codes in that file. /// /// Will panic if refresh_rate is `Some(0)`. To disable rate limiting use `None` instead. - pub fn term(term: Term, refresh_rate: u8) -> ProgressDrawTarget { - ProgressDrawTarget { + pub fn term(term: Term, refresh_rate: u8) -> Self { + Self { kind: TargetKind::Term { term, last_line_count: 0, @@ -75,8 +75,8 @@ impl ProgressDrawTarget { } /// Draw to a boxed object that implements the [`TermLike`] trait. - pub fn term_like(term_like: Box) -> ProgressDrawTarget { - ProgressDrawTarget { + pub fn term_like(term_like: Box) -> Self { + Self { kind: TargetKind::TermLike { inner: term_like, last_line_count: 0, @@ -88,8 +88,8 @@ impl ProgressDrawTarget { /// A hidden draw target. /// /// This forces a progress bar to be not rendered at all. - pub fn hidden() -> ProgressDrawTarget { - ProgressDrawTarget { + pub fn hidden() -> Self { + Self { kind: TargetKind::Hidden, } } @@ -225,10 +225,10 @@ impl TargetKind { /// Adjust `last_line_count` such that the next draw operation keeps/clears additional lines fn adjust_last_line_count(&mut self, adjust: LineAdjust) { let last_line_count: &mut usize = match self { - TargetKind::Term { + Self::Term { last_line_count, .. } => last_line_count, - TargetKind::TermLike { + Self::TermLike { last_line_count, .. } => last_line_count, _ => return, diff --git a/src/iter.rs b/src/iter.rs index 952207fd..2c5828f0 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -67,7 +67,7 @@ impl ProgressBarIter { /// Builder-like function for setting underlying progress bar's style. /// /// See [ProgressBar::with_style]. - pub fn with_style(mut self, style: ProgressStyle) -> ProgressBarIter { + pub fn with_style(mut self, style: ProgressStyle) -> Self { self.progress = self.progress.with_style(style); self } @@ -75,7 +75,7 @@ impl ProgressBarIter { /// Builder-like function for setting underlying progress bar's prefix. /// /// See [ProgressBar::with_prefix]. - pub fn with_prefix(mut self, prefix: impl Into>) -> ProgressBarIter { + pub fn with_prefix(mut self, prefix: impl Into>) -> Self { self.progress = self.progress.with_prefix(prefix); self } @@ -83,7 +83,7 @@ impl ProgressBarIter { /// Builder-like function for setting underlying progress bar's message. /// /// See [ProgressBar::with_message]. - pub fn with_message(mut self, message: impl Into>) -> ProgressBarIter { + pub fn with_message(mut self, message: impl Into>) -> Self { self.progress = self.progress.with_message(message); self } @@ -91,7 +91,7 @@ impl ProgressBarIter { /// Builder-like function for setting underlying progress bar's position. /// /// See [ProgressBar::with_position]. - pub fn with_position(mut self, position: u64) -> ProgressBarIter { + pub fn with_position(mut self, position: u64) -> Self { self.progress = self.progress.with_position(position); self } @@ -99,7 +99,7 @@ impl ProgressBarIter { /// Builder-like function for setting underlying progress bar's elapsed time. /// /// See [ProgressBar::with_elapsed]. - pub fn with_elapsed(mut self, elapsed: Duration) -> ProgressBarIter { + pub fn with_elapsed(mut self, elapsed: Duration) -> Self { self.progress = self.progress.with_elapsed(elapsed); self } diff --git a/src/multi.rs b/src/multi.rs index bfefcffe..30ed7a5d 100644 --- a/src/multi.rs +++ b/src/multi.rs @@ -14,8 +14,8 @@ pub struct MultiProgress { } impl Default for MultiProgress { - fn default() -> MultiProgress { - MultiProgress::with_draw_target(ProgressDrawTarget::stderr()) + fn default() -> Self { + Self::with_draw_target(ProgressDrawTarget::stderr()) } } @@ -25,13 +25,13 @@ impl MultiProgress { /// Progress bars added to this object by default draw directly to stderr, and refresh /// a maximum of 15 times a second. To change the refresh rate set the draw target to /// one with a different refresh rate. - pub fn new() -> MultiProgress { - MultiProgress::default() + pub fn new() -> Self { + Self::default() } /// Creates a new multi progress object with the given draw target. - pub fn with_draw_target(draw_target: ProgressDrawTarget) -> MultiProgress { - MultiProgress { + pub fn with_draw_target(draw_target: ProgressDrawTarget) -> Self { + Self { state: Arc::new(RwLock::new(MultiState::new(draw_target))), } } @@ -199,7 +199,7 @@ impl MultiState { ordering: vec![], draw_target, move_cursor: false, - alignment: Default::default(), + alignment: MultiProgressAlignment::default(), orphan_lines: Vec::new(), zombie_lines_count: 0, } @@ -251,7 +251,7 @@ impl MultiState { // Reap all consecutive 'zombie' progress bars from head of the list. let mut adjust = 0; - for &index in self.ordering.iter() { + for &index in &self.ordering { let member = &self.members[index]; if !member.is_zombie { break; @@ -299,7 +299,7 @@ impl MultiState { // Add lines from `ProgressBar::println` call. draw_state.lines.append(&mut self.orphan_lines); - for index in self.ordering.iter() { + for index in &self.ordering { let member = &self.members[*index]; if let Some(state) = &member.draw_state { draw_state.lines.extend_from_slice(&state.lines[..]); @@ -309,7 +309,7 @@ impl MultiState { drop(draw_state); let drawable = drawable.draw(); - for index in reap_indices.drain(..) { + for index in reap_indices { self.remove_idx(index); } @@ -362,15 +362,12 @@ impl MultiState { } fn insert(&mut self, location: InsertLocation) -> usize { - let idx = match self.free_set.pop() { - Some(idx) => { - self.members[idx] = MultiStateMember::default(); - idx - } - None => { - self.members.push(MultiStateMember::default()); - self.members.len() - 1 - } + let idx = if let Some(idx) = self.free_set.pop() { + self.members[idx] = MultiStateMember::default(); + idx + } else { + self.members.push(MultiStateMember::default()); + self.members.len() - 1 }; match location { diff --git a/src/progress_bar.rs b/src/progress_bar.rs index be69b012..60788f36 100644 --- a/src/progress_bar.rs +++ b/src/progress_bar.rs @@ -36,22 +36,22 @@ impl ProgressBar { /// This progress bar by default draws directly to stderr, and refreshes a maximum of 15 times /// a second. To change the refresh rate, set the draw target to one with a different refresh /// rate. - pub fn new(len: u64) -> ProgressBar { - ProgressBar::with_draw_target(Some(len), ProgressDrawTarget::stderr()) + pub fn new(len: u64) -> Self { + Self::with_draw_target(Some(len), ProgressDrawTarget::stderr()) } /// Creates a completely hidden progress bar /// /// This progress bar still responds to API changes but it does not have a length or render in /// any way. - pub fn hidden() -> ProgressBar { - ProgressBar::with_draw_target(None, ProgressDrawTarget::hidden()) + pub fn hidden() -> Self { + Self::with_draw_target(None, ProgressDrawTarget::hidden()) } /// Creates a new progress bar with a given length and draw target - pub fn with_draw_target(len: Option, draw_target: ProgressDrawTarget) -> ProgressBar { + pub fn with_draw_target(len: Option, draw_target: ProgressDrawTarget) -> Self { let pos = Arc::new(AtomicPosition::new()); - ProgressBar { + Self { state: Arc::new(Mutex::new(BarState::new(len, draw_target, pos.clone()))), pos, ticker: Arc::new(Mutex::new(None)), @@ -64,19 +64,19 @@ impl ProgressBar { } /// A convenience builder-like function for a progress bar with a given style - pub fn with_style(self, style: ProgressStyle) -> ProgressBar { + pub fn with_style(self, style: ProgressStyle) -> Self { self.set_style(style); self } /// A convenience builder-like function for a progress bar with a given tab width - pub fn with_tab_width(self, tab_width: usize) -> ProgressBar { + pub fn with_tab_width(self, tab_width: usize) -> Self { self.state().set_tab_width(tab_width); self } /// A convenience builder-like function for a progress bar with a given prefix - pub fn with_prefix(self, prefix: impl Into>) -> ProgressBar { + pub fn with_prefix(self, prefix: impl Into>) -> Self { let mut state = self.state(); state.state.prefix = TabExpandedString::new(prefix.into(), state.tab_width); drop(state); @@ -84,7 +84,7 @@ impl ProgressBar { } /// A convenience builder-like function for a progress bar with a given message - pub fn with_message(self, message: impl Into>) -> ProgressBar { + pub fn with_message(self, message: impl Into>) -> Self { let mut state = self.state(); state.state.message = TabExpandedString::new(message.into(), state.tab_width); drop(state); @@ -92,13 +92,13 @@ impl ProgressBar { } /// A convenience builder-like function for a progress bar with a given position - pub fn with_position(self, pos: u64) -> ProgressBar { + pub fn with_position(self, pos: u64) -> Self { self.state().state.set_pos(pos); self } /// A convenience builder-like function for a progress bar with a given elapsed time - pub fn with_elapsed(self, elapsed: Duration) -> ProgressBar { + pub fn with_elapsed(self, elapsed: Duration) -> Self { self.state().state.started = Instant::now() - elapsed; self } @@ -114,7 +114,7 @@ impl ProgressBar { /// [`ProgressBar`]: crate::ProgressBar /// [`ProgressBarIter`]: crate::ProgressBarIter /// [`ProgressBar::is_finished()`]: crate::ProgressBar::is_finished - pub fn with_finish(self, finish: ProgressFinish) -> ProgressBar { + pub fn with_finish(self, finish: ProgressFinish) -> Self { self.state().on_finish = finish; self } @@ -122,8 +122,8 @@ impl ProgressBar { /// Creates a new spinner /// /// This spinner by default draws directly to stderr. This adds the default spinner style to it. - pub fn new_spinner() -> ProgressBar { - let rv = ProgressBar::with_draw_target(None, ProgressDrawTarget::stderr()); + pub fn new_spinner() -> Self { + let rv = Self::with_draw_target(None, ProgressDrawTarget::stderr()); rv.set_style(ProgressStyle::default_spinner()); rv } @@ -197,7 +197,7 @@ impl ProgressBar { fn tick_inner(&self, now: Instant) { // Only tick if a `Ticker` isn't installed if self.ticker.lock().unwrap().is_none() { - self.state().tick(now) + self.state().tick(now); } } @@ -232,13 +232,13 @@ impl ProgressBar { /// [`suspend`]: ProgressBar::suspend /// [`MultiProgress`]: crate::MultiProgress pub fn println>(&self, msg: I) { - self.state().println(Instant::now(), msg.as_ref()) + self.state().println(Instant::now(), msg.as_ref()); } /// Update the `ProgressBar`'s inner [`ProgressState`] pub fn update(&self, f: impl FnOnce(&mut ProgressState)) { self.state() - .update(Instant::now(), f, self.ticker.lock().unwrap().is_none()) + .update(Instant::now(), f, self.ticker.lock().unwrap().is_none()); } /// Sets the position of the progress bar @@ -252,12 +252,12 @@ impl ProgressBar { /// Sets the length of the progress bar pub fn set_length(&self, len: u64) { - self.state().set_length(Instant::now(), len) + self.state().set_length(Instant::now(), len); } /// Increase the length of the progress bar pub fn inc_length(&self, delta: u64) { - self.state().inc_length(Instant::now(), delta) + self.state().inc_length(Instant::now(), delta); } /// Sets the current prefix of the progress bar @@ -294,17 +294,17 @@ impl ProgressBar { /// This can be useful if the progress bars made a large jump or was paused for a prolonged /// time. pub fn reset_eta(&self) { - self.state().reset(Instant::now(), Reset::Eta) + self.state().reset(Instant::now(), Reset::Eta); } /// Resets elapsed time pub fn reset_elapsed(&self) { - self.state().reset(Instant::now(), Reset::Elapsed) + self.state().reset(Instant::now(), Reset::Elapsed); } /// Resets all of the progress bar state pub fn reset(&self) { - self.state().reset(Instant::now(), Reset::All) + self.state().reset(Instant::now(), Reset::All); } /// Finishes the progress bar and leaves the current message @@ -319,7 +319,7 @@ impl ProgressBar { /// [`ProgressStyle`]). pub fn finish_with_message(&self, msg: impl Into>) { self.state() - .finish_using_style(Instant::now(), ProgressFinish::WithMessage(msg.into())) + .finish_using_style(Instant::now(), ProgressFinish::WithMessage(msg.into())); } /// Finishes the progress bar and completely clears it @@ -342,7 +342,7 @@ impl ProgressBar { self.state().finish_using_style( Instant::now(), ProgressFinish::AbandonWithMessage(msg.into()), - ) + ); } /// Finishes the progress bar using the behavior stored in the [`ProgressStyle`] @@ -566,8 +566,8 @@ impl WeakProgressBar { /// Create a new `WeakProgressBar` that returns `None` when [`upgrade`] is called. /// /// [`upgrade`]: WeakProgressBar::upgrade - pub fn new() -> WeakProgressBar { - Default::default() + pub fn new() -> Self { + Self::default() } /// Attempts to upgrade the Weak pointer to a [`ProgressBar`], delaying dropping of the inner diff --git a/src/state.rs b/src/state.rs index c4c06a08..48466a97 100644 --- a/src/state.rs +++ b/src/state.rs @@ -55,7 +55,7 @@ impl BarState { } ProgressFinish::Abandon => {} ProgressFinish::AbandonWithMessage(msg) => { - self.state.message = TabExpandedString::new(msg, self.tab_width) + self.state.message = TabExpandedString::new(msg, self.tab_width); } } @@ -77,7 +77,7 @@ impl BarState { self.state.pos.reset(now); self.state.status = Status::InProgress; - for (_, tracker) in self.style.format_map.iter_mut() { + for tracker in self.style.format_map.values_mut() { tracker.reset(&self.state, now); } @@ -126,7 +126,7 @@ impl BarState { self.state.est.record(pos, now); let _ = self.draw(false, now); - for (_, tracker) in self.style.format_map.iter_mut() { + for tracker in self.style.format_map.values_mut() { tracker.tick(&self.state, now); } } @@ -250,7 +250,7 @@ impl ProgressState { (0, _) => 0.0, (pos, Some(len)) => pos as f32 / len as f32, }; - pct.max(0.0).min(1.0) + pct.clamp(0.0, 1.0) } /// The expected ETA @@ -279,15 +279,14 @@ impl ProgressState { /// The number of steps per second pub fn per_sec(&self) -> f64 { - match self.status { - Status::InProgress => match 1.0 / self.est.seconds_per_step() { + if let Status::InProgress = self.status { + match 1.0 / self.est.seconds_per_step() { per_sec if per_sec.is_nan() => 0.0, per_sec => per_sec, - }, - _ => { - let len = self.len.unwrap_or_else(|| self.pos()); - len as f64 / self.started.elapsed().as_secs_f64() } + } else { + let len = self.len.unwrap_or_else(|| self.pos()); + len as f64 / self.started.elapsed().as_secs_f64() } } @@ -348,7 +347,7 @@ impl TabExpandedString { } pub(crate) fn set_tab_width(&mut self, new_tab_width: usize) { - if let TabExpandedString::WithTabs { + if let Self::WithTabs { original, expanded, tab_width, diff --git a/src/style.rs b/src/style.rs index 892b1f9b..98b9c05d 100644 --- a/src/style.rs +++ b/src/style.rs @@ -63,7 +63,7 @@ fn width(c: &[Box]) -> usize { impl ProgressStyle { /// Returns the default progress bar style for bars - pub fn default_bar() -> ProgressStyle { + pub fn default_bar() -> Self { Self::new(Template::from_str("{wide_bar} {pos}/{len}").unwrap()) } @@ -104,7 +104,7 @@ impl ProgressStyle { /// /// Note that the last character is used as the [final tick string][Self::get_final_tick_str()]. /// At least two characters are required to provide a non-final and final state. - pub fn tick_chars(mut self, s: &str) -> ProgressStyle { + pub fn tick_chars(mut self, s: &str) -> Self { self.tick_strings = s.chars().map(|c| c.to_string().into()).collect(); // Format bar will panic with some potentially confusing message, better to panic here // with a message explicitly informing of the problem @@ -119,7 +119,7 @@ impl ProgressStyle { /// /// Note that the last string is used as the [final tick string][Self::get_final_tick_str()]. /// At least two strings are required to provide a non-final and final state. - pub fn tick_strings(mut self, s: &[&str]) -> ProgressStyle { + pub fn tick_strings(mut self, s: &[&str]) -> Self { self.tick_strings = s.iter().map(|s| s.to_string().into()).collect(); // Format bar will panic with some potentially confusing message, better to panic here // with a message explicitly informing of the problem @@ -134,7 +134,7 @@ impl ProgressStyle { /// /// You can pass more than three for a more detailed display. /// All passed grapheme clusters need to be of equal width. - pub fn progress_chars(mut self, s: &str) -> ProgressStyle { + pub fn progress_chars(mut self, s: &str) -> Self { self.progress_chars = segment(s); // Format bar will panic with some potentially confusing message, better to panic here // with a message explicitly informing of the problem @@ -147,11 +147,7 @@ impl ProgressStyle { } /// Adds a custom key that owns a [`ProgressTracker`] to the template - pub fn with_key( - mut self, - key: &'static str, - f: S, - ) -> ProgressStyle { + pub fn with_key(mut self, key: &'static str, f: S) -> Self { self.format_map.insert(key, Box::new(f)); self } @@ -159,7 +155,7 @@ impl ProgressStyle { /// Sets the template string for the progress bar /// /// Review the [list of template keys](../index.html#templates) for more information. - pub fn template(mut self, s: &str) -> Result { + pub fn template(mut self, s: &str) -> Result { self.template = Template::from_str(s)?; Ok(self) } @@ -274,18 +270,18 @@ impl ProgressStyle { "prefix" => buf.push_str(state.prefix.expanded()), "pos" => buf.write_fmt(format_args!("{}", pos)).unwrap(), "human_pos" => { - buf.write_fmt(format_args!("{}", HumanCount(pos))).unwrap() + buf.write_fmt(format_args!("{}", HumanCount(pos))).unwrap(); } "len" => buf.write_fmt(format_args!("{}", len)).unwrap(), "human_len" => { - buf.write_fmt(format_args!("{}", HumanCount(len))).unwrap() + buf.write_fmt(format_args!("{}", HumanCount(len))).unwrap(); } "percent" => buf .write_fmt(format_args!("{:.*}", 0, state.fraction() * 100f32)) .unwrap(), "bytes" => buf.write_fmt(format_args!("{}", HumanBytes(pos))).unwrap(), "total_bytes" => { - buf.write_fmt(format_args!("{}", HumanBytes(len))).unwrap() + buf.write_fmt(format_args!("{}", HumanBytes(len))).unwrap(); } "decimal_bytes" => buf .write_fmt(format_args!("{}", DecimalBytes(pos))) @@ -294,10 +290,10 @@ impl ProgressStyle { .write_fmt(format_args!("{}", DecimalBytes(len))) .unwrap(), "binary_bytes" => { - buf.write_fmt(format_args!("{}", BinaryBytes(pos))).unwrap() + buf.write_fmt(format_args!("{}", BinaryBytes(pos))).unwrap(); } "binary_total_bytes" => { - buf.write_fmt(format_args!("{}", BinaryBytes(len))).unwrap() + buf.write_fmt(format_args!("{}", BinaryBytes(len))).unwrap(); } "elapsed_precise" => buf .write_fmt(format_args!("{}", FormattedDuration(state.elapsed()))) @@ -356,7 +352,7 @@ impl ProgressStyle { } TemplatePart::Literal(s) => cur.push_str(s.expanded()), TemplatePart::NewLine => { - self.push_line(lines, &mut cur, state, &mut buf, target_width, &wide) + self.push_line(lines, &mut cur, state, &mut buf, target_width, &wide); } } } @@ -478,7 +474,7 @@ impl Template { (Literal, c) => (Literal, Some(c)), (DoubleClose, '}') => (Literal, None), (MaybeOpen, '{') => (Literal, Some('{')), - (MaybeOpen, c) | (Key, c) if c.is_ascii_whitespace() => { + (MaybeOpen | Key, c) if c.is_ascii_whitespace() => { // If we find whitespace where the variable key is supposed to go, // backtrack and act as if this was a literal. buf.push(c); @@ -519,7 +515,7 @@ impl Template { (Width, None) } (Align, c @ '0'..='9') => (Width, Some(c)), - (Align, '!') | (Width, '!') => { + (Align | Width, '!') => { if let Some(TemplatePart::Placeholder { truncate, .. }) = parts.last_mut() { *truncate = true; } @@ -542,7 +538,7 @@ impl Template { (MaybeOpen, Key) if !buf.is_empty() => parts.push(TemplatePart::Literal( TabExpandedString::new(mem::take(&mut buf).into(), tab_width), )), - (Key, Align) | (Key, Literal) if !buf.is_empty() => { + (Key, Align | Literal) if !buf.is_empty() => { parts.push(TemplatePart::Placeholder { key: mem::take(&mut buf), align: Alignment::Left, @@ -550,15 +546,15 @@ impl Template { truncate: false, style: None, alt_style: None, - }) + }); } - (Width, FirstStyle) | (Width, Literal) if !buf.is_empty() => { + (Width, FirstStyle | Literal) if !buf.is_empty() => { if let Some(TemplatePart::Placeholder { width, .. }) = parts.last_mut() { *width = Some(buf.parse().unwrap()); buf.clear(); } } - (FirstStyle, AltStyle) | (FirstStyle, Literal) if !buf.is_empty() => { + (FirstStyle, AltStyle | Literal) if !buf.is_empty() => { if let Some(TemplatePart::Placeholder { style, .. }) = parts.last_mut() { *style = Some(Style::from_dotted_str(&buf)); buf.clear(); @@ -594,9 +590,9 @@ impl Template { } fn set_tab_width(&mut self, new_tab_width: usize) { - for part in self.parts.iter_mut() { + for part in &mut self.parts { if let TemplatePart::Literal(s) = part { - s.set_tab_width(new_tab_width) + s.set_tab_width(new_tab_width); } } } @@ -761,7 +757,7 @@ where fn reset(&mut self, _: &ProgressState, _: Instant) {} fn write(&self, state: &ProgressState, w: &mut dyn fmt::Write) { - (self)(state, w) + (self)(state, w); } } @@ -795,7 +791,7 @@ mod tests { } fn write(&self, _state: &ProgressState, w: &mut dyn fmt::Write) { - w.write_str(self.0.lock().unwrap().as_str()).unwrap() + w.write_str(self.0.lock().unwrap().as_str()).unwrap(); } }