2018-07-28 17:34:52 +02:00
|
|
|
#![warn(clippy::copy_iterator)]
|
2024-02-12 18:33:22 -05:00
|
|
|
#![allow(clippy::manual_inspect)]
|
2018-07-17 19:22:55 +02:00
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
|
struct Countdown(u8);
|
|
|
|
|
|
|
|
|
|
impl Iterator for Countdown {
|
2025-02-12 23:44:38 +01:00
|
|
|
//~^ copy_iterator
|
2025-02-11 17:57:08 +01:00
|
|
|
|
2018-07-17 19:22:55 +02:00
|
|
|
type Item = u8;
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<u8> {
|
|
|
|
|
self.0.checked_sub(1).map(|c| {
|
|
|
|
|
self.0 = c;
|
|
|
|
|
c
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let my_iterator = Countdown(5);
|
2021-05-03 23:58:41 -07:00
|
|
|
assert_eq!(my_iterator.take(1).count(), 1);
|
|
|
|
|
assert_eq!(my_iterator.count(), 5);
|
2018-07-17 19:22:55 +02:00
|
|
|
}
|