Created
June 25, 2019 14:54
-
-
Save rust-play/b72dc11d0be75bcf694054b819f3e828 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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 iterate_with_iterator<T: std::fmt::Display, I: Iterator<Item = T>>(iter: I) { | |
for x in iter { | |
println!("{}", x); | |
} | |
} | |
fn iterate_with_boxed_iterator<'a, T: std::fmt::Display>(iter: Box<dyn Iterator<Item = T> + 'a>) { | |
for x in iter { | |
println!("{}", x); | |
} | |
} | |
fn iterate_with_deref_boxed_iterator<'a, T: std::fmt::Display>(iter: Box<dyn Iterator<Item = T> + 'a>) { | |
let diter = *iter; | |
for x in diter { | |
println!("{}", x); | |
} | |
} | |
fn main() { | |
let test = String::from("test"); | |
iterate_with_iterator(test.chars()); | |
iterate_with_boxed_iterator(Box::new(test.chars())); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment