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

Add builder methods for ProgressBarIter #337

Merged
merged 1 commit into from Dec 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/iter.rs
@@ -1,7 +1,10 @@
use crate::progress_bar::ProgressBar;
use crate::style::ProgressStyle;
use std::borrow::Cow;
use std::convert::TryFrom;
use std::io::{self, IoSliceMut};
use std::iter::FusedIterator;
use std::time::Duration;
#[cfg(feature = "tokio")]
use std::{
pin::Pin,
Expand Down Expand Up @@ -59,6 +62,48 @@ pub struct ProgressBarIter<T> {
pub progress: ProgressBar,
}

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> {
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> {
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> {
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> {
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> {
self.progress = self.progress.with_elapsed(elapsed);
self
}
}

impl<S, T: Iterator<Item = S>> Iterator for ProgressBarIter<T> {
type Item = S;

Expand Down