Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address a bunch of lints #498

Merged
merged 9 commits into from
Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/multi-tree-ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/multi-tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<&Elem>>) -> Option<Action> {
fn get_action(rng: &mut dyn RngCore, tree: &Mutex<Vec<&Elem>>) -> Option<Action> {
let elem_len = ELEMENTS.len() as u64;
let list_len = tree.lock().unwrap().len() as u64;
let sum_free = tree
Expand Down
32 changes: 16 additions & 16 deletions src/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RwLock<MultiState>>, idx: usize) -> Self {
Expand All @@ -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,
Expand All @@ -75,8 +75,8 @@ impl ProgressDrawTarget {
}

/// Draw to a boxed object that implements the [`TermLike`] trait.
pub fn term_like(term_like: Box<dyn TermLike>) -> ProgressDrawTarget {
ProgressDrawTarget {
pub fn term_like(term_like: Box<dyn TermLike>) -> Self {
Self {
kind: TargetKind::TermLike {
inner: term_like,
last_line_count: 0,
Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,39 @@ impl<T> ProgressBarIter<T> {
/// Builder-like function for setting underlying progress bar's style.
///
/// See [ProgressBar::with_style].
pub fn with_style(mut self, style: ProgressStyle) -> ProgressBarIter<T> {
pub fn with_style(mut self, style: ProgressStyle) -> Self {
self.progress = self.progress.with_style(style);
self
}

/// Builder-like function for setting underlying progress bar's prefix.
///
/// See [ProgressBar::with_prefix].
pub fn with_prefix(mut self, prefix: impl Into<Cow<'static, str>>) -> ProgressBarIter<T> {
pub fn with_prefix(mut self, prefix: impl Into<Cow<'static, str>>) -> Self {
self.progress = self.progress.with_prefix(prefix);
self
}

/// Builder-like function for setting underlying progress bar's message.
///
/// See [ProgressBar::with_message].
pub fn with_message(mut self, message: impl Into<Cow<'static, str>>) -> ProgressBarIter<T> {
pub fn with_message(mut self, message: impl Into<Cow<'static, str>>) -> Self {
self.progress = self.progress.with_message(message);
self
}

/// Builder-like function for setting underlying progress bar's position.
///
/// See [ProgressBar::with_position].
pub fn with_position(mut self, position: u64) -> ProgressBarIter<T> {
pub fn with_position(mut self, position: u64) -> Self {
self.progress = self.progress.with_position(position);
self
}

/// Builder-like function for setting underlying progress bar's elapsed time.
///
/// See [ProgressBar::with_elapsed].
pub fn with_elapsed(mut self, elapsed: Duration) -> ProgressBarIter<T> {
pub fn with_elapsed(mut self, elapsed: Duration) -> Self {
self.progress = self.progress.with_elapsed(elapsed);
self
}
Expand Down
35 changes: 16 additions & 19 deletions src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand All @@ -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))),
}
}
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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[..]);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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 {
Expand Down
Loading