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

Accept items by iterator instead of slice #299

Merged
merged 2 commits into from
Jan 18, 2024

Conversation

jacobtread
Copy link
Contributor

Description

Replaces the handling for adding multiple items to the Select, FuzzySelect, MultiSelect, and Sort they currently take a slice containing any number of values that can be converted into String through ToString, this change replaces taking a slice with instead taking anything that implement IntoIterator where the item is ToString.

This allows the items function to take any collection of values rather than only allowing slices, thus making something like the following possible:

struct MyItem {
  name: String,
  // .. other struct items
}

let collection: Vec<MyItem> = vec![  /* Some list of items */ ];
let item_names = collection
  .iter()
  .map(|item| item.name.as_str());

Select::new()
  .items(item_names);

Changes

  • Make items, items_checked (and similar functions) accept an iterator instead of a slice
  • Add tests for the new iterator items function

@pksunkara pksunkara merged commit 97a840f into console-rs:master Jan 18, 2024
7 checks passed
@Gordon01
Copy link
Contributor

I believe #223 may now be closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants