Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. use std::iter::{Repeat, repeat};
  2.  
  3. struct InfiniteUnit;
  4.  
  5. struct ConstUnit<T: Clone>(T);
  6.  
  7. impl<T: Clone> Iterator for ConstUnit<T> {
  8. type Item = T;
  9. fn next(&mut self) -> Option<Self::Item> {
  10. Some(self.0.clone())
  11. }
  12. }
  13.  
  14. impl IntoIterator for InfiniteUnit {
  15. type Item = u32;
  16. type IntoIter = Repeat<u32>;
  17.  
  18. fn into_iter(self) -> Self::IntoIter {
  19. repeat(22)
  20. }
  21. }
  22.  
  23. fn main() {
  24. let mut count = 0;
  25. for _ in InfiniteUnit {
  26. count += 1;
  27. println!("count == {}", count);
  28. if count >= 5 {
  29. break;
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement