konst_kernel/macros/
into_iter_macros.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#[doc(hidden)]
#[macro_export]
macro_rules! iterator_shared {
    (
        is_forward = $is_forward:ident,
        item = $Item:ty,
        iter_forward = $Self:ty,
        $(iter_reversed = $Rev:path,)?
        next($self:ident) $next_block:block,
        $(next_back $next_back_block:block,)?
        fields = $fields:tt,
    ) => {
        /// Creates a clone of this iterator
        pub const fn copy(&self) -> Self {
            let Self $fields = *self;
            Self $fields
        }

        $(
            /// Reverses the iterator
            pub const fn rev(self) -> $crate::__choose!($is_forward $Rev $Self) {
                let Self $fields = self;
                type Type<T> = T;
                Type::<$crate::__choose!($is_forward $Rev $Self)> $fields
            }
        )?

        /// Advances the iterator and returns the next value.
        #[track_caller]
        pub const fn next(mut $self) -> Option<($Item, Self)> {
            $crate::__choose!{
                $is_forward
                $next_block
                $($next_back_block)?
            }
        }

        $(
            /// Removes and returns an element from the end of the iterator.
            #[track_caller]
            pub const fn next_back(mut $self) -> Option<($Item, Self)> {
                $crate::__choose!{
                    $is_forward
                    $next_back_block
                    $next_block
                }
            }
        )?
    };
}