devela/data/iter/
namespace.rs

1// devela::data::iter::namespace
2//
3//! Defines the [`Iter`] namespace.
4//
5// WAIT: [iter_chain](https://github.com/rust-lang/rust/issues/125964)
6
7// #[cfg(feature = "nightly_coro")]
8// use core::iter::from_coroutine;
9use core::iter::{empty, from_fn, once, once_with, repeat, repeat_n, repeat_with, successors, zip};
10
11#[doc = crate::TAG_NAMESPACE!()]
12#[doc = crate::TAG_ITERATOR!()]
13/// Iterator-related namespaced operations.
14pub struct Iter;
15
16/// # Core methods.
17impl Iter {
18    /// Creates an iterator that yields nothing.
19    ///
20    /// See `core::iter::`[`empty`].
21    pub const fn empty<T>() -> crate::IterEmpty<T> {
22        empty()
23    }
24
25    // WAIT: https://github.com/rust-lang/rust/pull/135687
26    // /// Creates a new iterator where each iteration calls the provided coroutine.
27    // ///
28    // /// See `core::iter::`[`from_corooutine`].
29    // #[cfg(feature = "nightly_coro")]
30    // #[cfg_attr(feature = "nightly_doc", doc(cfg(feature = "nightly_coro")))]
31    // pub fn from_coroutine<G>(coroutine: G) -> core::iter::FromCoroutine<G>
32    // where
33    //     G: crate::Coroutine<Return = ()> + Unpin,
34    // {
35    //     from_coroutine
36    // }
37
38    /// Creates an iterator that calls the given closure `F: FnMut() -> Option<T>`.
39    ///
40    /// See `core::iter::`[`from_fn`].
41    pub fn from_fn<T, F>(f: F) -> crate::IterFromFn<F>
42    where
43        F: FnMut() -> Option<T>,
44    {
45        from_fn(f)
46    }
47
48    /// Creates an iterator that yields an element exactly once.
49    ///
50    /// See `core::iter::`[`once`].
51    pub fn once<T>(value: T) -> crate::IterOnce<T> {
52        once(value)
53    }
54
55    /// Creates an iterator that lazily generates a value exactly once.
56    ///
57    /// See `core::iter::`[`once_with`].
58    pub fn once_with<A, F>(make: F) -> crate::IterOnceWith<F>
59    where
60        F: FnOnce() -> A,
61    {
62        once_with(make)
63    }
64
65    /// Creates an iterator that endlessly repeats a single element.
66    ///
67    /// See `core::iter::`[`repeat`].
68    pub fn repeat<T>(elt: T) -> crate::IterRepeat<T>
69    where
70        T: Clone,
71    {
72        repeat(elt)
73    }
74
75    /// Creates a new iterator that repeats a single element a given number of times.
76    ///
77    /// See `core::iter::`[`repeat_n`].
78    pub fn repeat_n<T>(element: T, count: usize) -> crate::IterRepeatN<T>
79    where
80        T: Clone,
81    {
82        repeat_n(element, count)
83    }
84
85    /// Creates an iterator that endlessly repeats calling `F: FnMut() -> A`.
86    ///
87    /// See `core::iter::`[`repeat_with`].
88    pub fn repeat_with<A, F>(repeater: F) -> crate::IterRepeatWith<F>
89    where
90        F: FnMut() -> A,
91    {
92        repeat_with(repeater)
93    }
94
95    /// Creates an iterator where each successive item is computed based on the previous.
96    ///
97    /// See `core::iter::`[`successors`].
98    pub fn successors<T, F>(first: Option<T>, succ: F) -> crate::IterSuccessors<T, F>
99    where
100        F: FnMut(&T) -> Option<T>,
101    {
102        successors(first, succ)
103    }
104
105    /// Converts the arguments to iterators and zips them.
106    ///
107    /// See `core::iter::`[`zip`].
108    pub fn zip<A, B>(
109        a: A,
110        b: B,
111    ) -> crate::IterZip<<A as IntoIterator>::IntoIter, <B as IntoIterator>::IntoIter>
112    where
113        A: IntoIterator,
114        B: IntoIterator,
115    {
116        zip(a, b)
117    }
118}
119
120/// # `itertool` methods.
121///
122/// ## Features
123/// They depend on enabling the `dep_itertools` feature.
124#[cfg(feature = "dep_itertools")]
125impl Iter {}