用 use<> 精确捕获

版本新特性 / Rust 1.82

// *** before: ***
// what the returned impl Trait captured was said in a roundabout way:
// by a witness type or by an extra lifetime parameter
fn ids<'a>(v: &'a [String]) -> impl Iterator<Item = usize> + 'a {
    0..v.len()
}

// *** in version 1.82: ***
// the capture list is written out: empty means nothing is held
fn ids(v: &[String]) -> impl Iterator<Item = usize> + use<> {
    0..v.len()
}

fn names<'a>(v: &'a [String]) -> impl Iterator<Item = &'a String> + use<'a> {
    v.iter()
}