Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created April 23, 2019 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/8eda1e8c617e5ced01079df7094db798 to your computer and use it in GitHub Desktop.
Save rust-play/8eda1e8c617e5ced01079df7094db798 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
fn main() {
let filter = "Joh";
let names = vec!["John", "Jane", "Johnny"];
let lowered_filter = filter.to_lowercase();
let filterNames = |x: &&str| -> bool {
x.to_lowercase().contains(&lowered_filter)
};
let filtered: Vec<&str> = names.iter().cloned().filter(filterNames).collect();
println!("List {:?}", filtered);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment