2023-02-26 01:18:08 +00:00
|
|
|
#![allow(unused)]
|
|
|
|
#![warn(clippy::unused_enumerate_index)]
|
|
|
|
|
2023-10-12 17:05:22 +00:00
|
|
|
use std::iter::Enumerate;
|
|
|
|
|
2023-02-26 01:18:08 +00:00
|
|
|
fn main() {
|
|
|
|
let v = [1, 2, 3];
|
|
|
|
for (_, x) in v.iter().enumerate() {
|
2023-10-12 17:05:22 +00:00
|
|
|
println!("{x}");
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Dummy1;
|
|
|
|
impl Dummy1 {
|
|
|
|
fn enumerate(self) -> Vec<usize> {
|
|
|
|
vec![]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let dummy = Dummy1;
|
|
|
|
for x in dummy.enumerate() {
|
|
|
|
println!("{x}");
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Dummy2;
|
|
|
|
impl Dummy2 {
|
|
|
|
fn enumerate(self) -> Enumerate<std::vec::IntoIter<usize>> {
|
|
|
|
vec![1, 2].into_iter().enumerate()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let dummy = Dummy2;
|
|
|
|
for (_, x) in dummy.enumerate() {
|
|
|
|
println!("{x}");
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut with_used_iterator = [1, 2, 3].into_iter().enumerate();
|
|
|
|
with_used_iterator.next();
|
|
|
|
for (_, x) in with_used_iterator {
|
|
|
|
println!("{x}");
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Dummy3(std::vec::IntoIter<usize>);
|
|
|
|
|
|
|
|
impl Iterator for Dummy3 {
|
|
|
|
type Item = usize;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
self.0.next()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
|
|
self.0.size_hint()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let dummy = Dummy3(vec![1, 2, 3].into_iter());
|
|
|
|
for (_, x) in dummy.enumerate() {
|
|
|
|
println!("{x}");
|
2023-02-26 01:18:08 +00:00
|
|
|
}
|
|
|
|
}
|