一、自定义迭代器

实现 Iterator trait 即可

pub struct Counter {
    pub count: usize,
}

impl Iterator for Counter {
    type Item = usize;
    fn next(&mut self) -> Option<Self::Item> {
        self.count += 1;
        if self.count < 6 {
            Some(self.count)
        } else {
            None
        }
    }
}

  

 

233

相关文章:

  • 2021-11-20
  • 2022-01-18
  • 2021-08-19
  • 2021-09-16
  • 2022-02-11
猜你喜欢
  • 2022-12-23
  • 2021-06-08
  • 2022-12-23
  • 2021-10-30
  • 2021-09-24
  • 2021-07-04
相关资源
相似解决方案