console-rs / dialoguer

Rust utility library for nice command line prompts and similar things
MIT License
1.31k stars 143 forks source link

Accept items by iterator instead of slice #299

Closed jacobtread closed 7 months ago

jacobtread commented 8 months ago

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

Gordon01 commented 7 months ago

I believe https://github.com/console-rs/dialoguer/pull/223 may now be closed