| 1 | /// Creates a new closure that returns an iterator where each iteration steps the given |
| 2 | /// generator to the next `yield` statement. |
| 3 | /// |
| 4 | /// Similar to [`iter::from_fn`], but allows arbitrary control flow. |
| 5 | /// |
| 6 | /// [`iter::from_fn`]: crate::iter::from_fn |
| 7 | /// |
| 8 | /// # Examples |
| 9 | /// |
| 10 | /// ``` |
| 11 | /// #![feature(iter_macro, coroutines)] |
| 12 | /// |
| 13 | /// let it = std::iter::iter!{|| { |
| 14 | /// yield 1; |
| 15 | /// yield 2; |
| 16 | /// yield 3; |
| 17 | /// } }(); |
| 18 | /// let v: Vec<_> = it.collect(); |
| 19 | /// assert_eq!(v, [1, 2, 3]); |
| 20 | /// ``` |
| 21 | #[unstable (feature = "iter_macro" , issue = "none" , reason = "generators are unstable" )] |
| 22 | #[allow_internal_unstable (coroutines, iter_from_coroutine)] |
| 23 | #[rustc_builtin_macro ] |
| 24 | pub macro iter($($t:tt)*) { |
| 25 | /* compiler-builtin */ |
| 26 | } |
| 27 | |