Skip to content

Instantly share code, notes, and snippets.

@n1xx1
Created January 29, 2019 02:00
Show Gist options
  • Save n1xx1/6024c60e349274a25364cdc58515f25a to your computer and use it in GitHub Desktop.
Save n1xx1/6024c60e349274a25364cdc58515f25a to your computer and use it in GitHub Desktop.
Rust return generic Iterator
fn wrap_vec<'a, T>(v: &'a Vec<T>) -> impl Iterator<Item = String> + 'a where T: std::fmt::Display {
v.iter().map(|s| format!("<{}>", s))
}
fn main() {
let a = vec!["a", "b", "c"];
for s in wrap_vec(&a) {
println!("{}", s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment