Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. use std::cell::Cell;
  2.  
  3. fn main() {
  4. let n = &Cell::new(5);
  5. let c = &Cell::new(0);
  6.  
  7. let it = std::iter::from_fn(|| {
  8. let x = c.get();
  9. if x == 0 {
  10. let x = n.get();
  11. n.set(x - 1);
  12. c.set(x);
  13. None
  14. } else {
  15. c.set(x - 1);
  16. Some(x)
  17. }
  18. });
  19. let it = it.cycle();
  20. it.for_each(|x| {
  21. dbg!(x);
  22. });
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement