Created
January 29, 2019 02:00
-
-
Save n1xx1/6024c60e349274a25364cdc58515f25a to your computer and use it in GitHub Desktop.
Rust return generic Iterator
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
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