Skip to content

Instantly share code, notes, and snippets.

@JEG2
Created August 28, 2014 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JEG2/f66885b04bd5ae8fe714 to your computer and use it in GitHub Desktop.
Save JEG2/f66885b04bd5ae8fe714 to your computer and use it in GitHub Desktop.
A type question abou Rust.
// 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