I have a function that I wish to map an array to another.
Here is some simplified code that exhibits the problem. (The map does nothing; the function is useless, except to demonstrate the error.) When I un-comment the assignment, it works perfectly. However, when I try to pass in the array from outside the function it does not.
fn main(){
let args = ["a1", "b1"];
f( &args );
}
fn f ( args: &[&str] ) {
//let args = ["a2", "b2"];
println!("{args:?}");
let args = args.map(
|v| v
);
println!("{args:?}")
}
The cause of the error may be that a slice is passed. This makes sense as I will need to be able to process arrays of different lengths. And, slice does not seem to have a map function. However, I do not know how to fix it, or if my assessment is correct.
args.iter().map(...)mapdoes something useful, and instead of callingprintln, it calls another function that also does not mutate the data.