Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::iter::{Repeat, repeat};
- struct InfiniteUnit;
- struct ConstUnit<T: Clone>(T);
- impl<T: Clone> Iterator for ConstUnit<T> {
- type Item = T;
- fn next(&mut self) -> Option<Self::Item> {
- Some(self.0.clone())
- }
- }
- impl IntoIterator for InfiniteUnit {
- type Item = u32;
- type IntoIter = Repeat<u32>;
- fn into_iter(self) -> Self::IntoIter {
- repeat(22)
- }
- }
- fn main() {
- let mut count = 0;
- for _ in InfiniteUnit {
- count += 1;
- println!("count == {}", count);
- if count >= 5 {
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement