konst_macro_rules/
internal_macros.rs

1#[doc(hidden)]
2#[macro_export]
3macro_rules! iterator_shared {
4    (
5        is_forward = $is_forward:ident,
6        item = $Item:ty,
7        iter_forward = $Self:ty,
8        $(iter_reversed = $Rev:path,)?
9        next($self:ident) $next_block:block,
10        $(next_back $next_back_block:block,)?
11        fields = $fields:tt,
12    ) => {
13        /// Creates a clone of this iterator
14        pub const fn copy(&self) -> Self {
15            let Self $fields = *self;
16            Self $fields
17        }
18
19        $(
20            /// Reverses the iterator
21            pub const fn rev(self) -> $crate::__choose!($is_forward $Rev $Self) {
22                let Self $fields = self;
23                type Type<T> = T;
24                Type::<$crate::__choose!($is_forward $Rev $Self)> $fields
25            }
26        )?
27
28        /// Advances the iterator and returns the next value.
29        pub const fn next(mut $self) -> Option<($Item, Self)> {
30            $crate::__choose!{
31                $is_forward
32                $next_block
33                $($next_back_block)?
34            }
35        }
36
37        $(
38            /// Removes and returns an element from the end of the iterator.
39            pub const fn next_back(mut $self) -> Option<($Item, Self)> {
40                $crate::__choose!{
41                    $is_forward
42                    $next_back_block
43                    $next_block
44                }
45            }
46        )?
47    };
48}
49
50#[doc(hidden)]
51#[macro_export]
52macro_rules! __choose {
53    (true $then:tt $($else:tt)*) => {
54        $then
55    };
56    (false $then:tt $else:tt) => {
57        $else
58    };
59}