Created
August 28, 2014 14:34
-
-
Save JEG2/f66885b04bd5ae8fe714 to your computer and use it in GitHub Desktop.
A type question abou Rust.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The uncommented version of increment_all() works. What I'm trying to | |
// understand is why I can't handle the return type as shown in the commented | |
// out version, which does not compile. | |
// fn increment_all<I: Iterator<int>>(numbers: I) -> I /* or Iterator<int> */ { | |
fn increment_all<'r, I: Iterator<int>>(numbers: I) -> std::iter::Map<'r, int, int, I> { | |
numbers.map(|n| n + 1) | |
} | |
fn main() { | |
let before = vec![1i, 2, 3]; | |
let after: Vec<int> = increment_all(before.iter().map(|&n| n)).collect(); | |
println!("{}", after); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment