In Rust, how do I avoid writing for loops and let statement? This program is used to record which line of text the string appears on and the position it appears on the line.
I know I can use iterators and map to eliminate them, but I just contacted Rust, I don't know how to write it.
pub struct L{
x: usize,
y: usize,
}
pub fn foo (text: &str, string: &str)->Vec<L> {
let mut r= Vec::new();
let mut x=0;
for line in text.lines(){
for (y, _) in line.match_indices(string){
r.push(L{
x : x,
y: y, })
}
x+=1;
}
r
}