Closed
Description
The text says that B
in the section on .map()
is of type Self
; this is incorrect.
Consider the following demonstration (this code compiles under Rust 2018 as a drop in for the contents of main.rs after cargo new mapdemo --bin; cargo run
):
fn main() {
let x = [1, 2, 3, 4, 5];
let z = x.iter().map(|&x| format!("{}", x)).collect::<Vec<String>>();
println!("{:?}", z);
}
The self
argument to map will be an Iter<u64>
. The Self::Item
type is therefore u64
. The return type of the function being passed to map is String
. This is what the B
type variable indicates: the return type of the function, as can be clearly seen in the second line of the where
clause in your example:
F: FnMut(Self::Item) -> B
I have left a pull request: #42
Metadata
Metadata
Assignees
Labels
No labels