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

Rewrite several prompts to take IntoIterator<Item: ToString> instead of &[T] #223

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion src/prompts/fuzzy_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ impl FuzzySelect<'_> {
}

/// Adds multiple items to the fuzzy selector.
pub fn items<T: ToString>(&mut self, items: &[T]) -> &mut Self {
pub fn items<T>(&mut self, items: T) -> &mut Self
where
T: IntoIterator,
T::Item: std::string::ToString,
pksunkara marked this conversation as resolved.
Show resolved Hide resolved
{
for item in items {
self.items.push(item.to_string());
}
Expand Down
14 changes: 11 additions & 3 deletions src/prompts/multi_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ impl MultiSelect<'_> {
}

/// Adds multiple items to the selector.
pub fn items<T: ToString>(&mut self, items: &[T]) -> &mut Self {
pub fn items<T>(&mut self, items: T) -> &mut Self
where
T: IntoIterator,
T::Item: std::string::ToString,
{
for item in items {
self.items.push(item.to_string());
self.defaults.push(false);
Expand All @@ -100,8 +104,12 @@ impl MultiSelect<'_> {
}

/// Adds multiple items to the selector with checked state
pub fn items_checked<T: ToString>(&mut self, items: &[(T, bool)]) -> &mut Self {
for &(ref item, checked) in items {
pub fn items_checked<T, I>(&mut self, items: T) -> &mut Self
where
I: std::string::ToString,
T: IntoIterator<Item = (I, bool)>,
pksunkara marked this conversation as resolved.
Show resolved Hide resolved
{
for (item, checked) in items {
self.items.push(item.to_string());
self.defaults.push(checked);
}
Expand Down
6 changes: 5 additions & 1 deletion src/prompts/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ impl Select<'_> {
/// Ok(())
/// }
/// ```
pub fn items<T: ToString>(&mut self, items: &[T]) -> &mut Self {
pub fn items<T: ToString>(&mut self, items: T) -> &mut Self
where
T: IntoIterator,
T::Item: std::string::ToString,
{
for item in items {
self.items.push(item.to_string());
}
Expand Down
6 changes: 5 additions & 1 deletion src/prompts/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ impl Sort<'_> {
}

/// Adds multiple items to the selector.
pub fn items<T: ToString>(&mut self, items: &[T]) -> &mut Self {
pub fn items<T>(&mut self, items: T) -> &mut Self
where
T: IntoIterator,
T::Item: std::string::ToString,
{
for item in items {
self.items.push(item.to_string());
}
Expand Down