Is this the idiomatic way to reduce `&`

fn main() {
    // `<slice as IntoIterator>::Item` is `&&str` type
    let v: Vec<&&str> = ["a", "b"][..].into_iter().collect(); 
    need_one_iterator(v.iter().map(|&&s| s));
    need_one_iterator(v.into_iter().map(|&s| s));

// but this function needs an iterator yielding `&str`
fn need_one_iterator<'i>(_: impl Iterator<Item = &'i str>) {} 


Using .map and reference pattern is the only way I can think of here.

You can use .copied() instead.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.