2018-07-28 10:34:52 -05:00
|
|
|
#![warn(clippy::copy_iterator)]
|
2024-06-27 11:56:04 -05:00
|
|
|
#![allow(clippy::manual_inspect)]
|
2018-07-17 12:22:55 -05:00
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
struct Countdown(u8);
|
|
|
|
|
|
|
|
impl Iterator for Countdown {
|
2023-08-24 14:32:12 -05:00
|
|
|
//~^ ERROR: you are implementing `Iterator` on a `Copy` type
|
|
|
|
//~| NOTE: consider implementing `IntoIterator` instead
|
2018-07-17 12:22:55 -05: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-06 04:51:22 -05:00
|
|
|
assert_eq!(my_iterator.take(1).count(), 1);
|
|
|
|
assert_eq!(my_iterator.count(), 5);
|
2018-07-17 12:22:55 -05:00
|
|
|
}
|