What is an idiomatic way to collect an iterator of &T into a collection of Ts?
问题 I need to collect an iterator over a slice of &str s into a collection of &str s. The problem is that the iterator yields &&str s. I tried to map from &word to word , and while it works, I don't know if it is considered good or if there are better options available. The problem: use std::collections::HashSet; fn main() { let words = &["hello", "world", "I'm", "a", "Rustacean!"]; let hashset = words.iter().collect::<HashSet<&str>>(); } Playground error[E0277]: a collection of type `std: