Skip to main content

oxilean_runtime/lazy_eval/
takeiter_traits.rs

1//! # TakeIter - Trait Implementations
2//!
3//! This module contains trait implementations for `TakeIter`.
4//!
5//! ## Implemented Traits
6//!
7//! - `Iterator`
8//!
9//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
10
11use super::types::TakeIter;
12use std::fmt;
13
14impl<T: Clone + fmt::Debug + 'static> Iterator for TakeIter<T> {
15    type Item = T;
16    fn next(&mut self) -> Option<Self::Item> {
17        if self.remaining == 0 {
18            return None;
19        }
20        let (head, tail_fn) = self.current.take()?;
21        self.remaining -= 1;
22        if let Some(f) = &tail_fn {
23            let next_list = f();
24            if let Some(h) = next_list.head {
25                self.current = Some((h, next_list.tail));
26            }
27        }
28        Some(head)
29    }
30}