iter/
iter.rs

1use gat_std::iter::Iterator;
2use gat_std_proc::gatify;
3
4struct Custom(i32, i32);
5
6impl Custom {
7    fn new() -> Custom {
8        Custom(10, 0)
9    }
10}
11
12impl Iterator for Custom {
13    type Item<'a> = &'a mut i32
14    where
15        Self: 'a;
16
17    fn next(&mut self) -> Option<Self::Item<'_>> {
18        if self.0 > 0 {
19            self.0 -= 1;
20            Some(&mut self.1)
21        } else {
22            None
23        }
24    }
25}
26
27fn main() {
28    let iter: Custom = Custom::new();
29
30    iter.touch(|val| {
31        **val += 1;
32    })
33    .for_each(|val| println!("{}", *val));
34}
35
36#[gatify]
37fn _foo() {
38    // STD iterator
39    for _ in 0..10 {}
40    // Lending iterator
41    for _ in Custom::new() {}
42}
43
44#[gatify]
45fn _bar<T: core::iter::IntoIterator>(val: T) {
46    for _ in val {}
47}
48
49#[gatify]
50fn _baz<T: gat_std::iter::IntoIterator>(val: T) {
51    for _ in val {}
52}