iter_tools/
iter.rs

1// #[ cfg( not( feature = "no_std" ) ) ]
2mod private 
3{
4  #[ allow( unused_imports ) ]
5  use crate :: *;
6  // use ::itertools ::process_results;
7
8  #[ cfg( feature = "iter_trait" ) ]
9  use clone_dyn_types ::CloneDyn;
10
11  /// Trait that encapsulates an iterator with specific characteristics and implemetning `CloneDyn`.
12  ///
13  /// The `_IterTrait` trait is designed to represent iterators that may yield references to items ( `&'a T` ).
14  /// These iterators must also implement the `ExactSizeIterator` and `DoubleEndedIterator` traits.
15  /// This combination ensures that the iterator can :
16  /// - Provide an exact size hint ( `ExactSizeIterator` ),
17  /// - Be traversed from both ends ( `DoubleEndedIterator` ).
18  ///
19  /// Additionally, the iterator must implement the `CloneDyn` trait, which allows cloning of trait objects.
20  ///
21  /// # Example
22  /// ```rust
23  /// use iter_tools ::_IterTrait;
24  ///
25  /// // Example struct that implements Iterator, ExactSizeIterator, DoubleEndedIterator, and CloneDyn.
26  /// #[ derive( Clone ) ]
27  /// struct MyIterator
28  /// {
29  ///   // internal fields
30  /// }
31  ///
32  /// impl Iterator for MyIterator
33  /// {
34  ///   type Item = i32;
35  ///
36  ///   fn next( &mut self ) -> Option< Self ::Item >
37  ///   {
38  ///     // implementation
39  ///     Some( 1 )
40  /// }
41  /// }
42  ///
43  /// impl ExactSizeIterator for MyIterator
44  /// {
45  ///   fn len( &self ) -> usize
46  ///   {
47  ///     // implementation
48  ///     1
49  /// }
50  /// }
51  ///
52  /// impl DoubleEndedIterator for MyIterator
53  /// {
54  ///   fn next_back( &mut self ) -> Option< Self ::Item >
55  ///   {
56  ///     // implementation
57  ///     Some( 1 )
58  /// }
59  /// }
60  ///
61  /// ```
62  #[ cfg( feature = "iter_trait" ) ]
63  pub trait _IterTrait< 'a, T >
64  where
65  T: 'a,
66  Self: Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator,
67  Self: CloneDyn,
68  {
69 }
70
71  #[ cfg( feature = "iter_trait" ) ]
72  impl< 'a, T, I > _IterTrait< 'a, T > for I
73  where
74  T: 'a,
75  Self: Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator,
76  Self: CloneDyn,
77  {
78 }
79
80  /// Trait that encapsulates a clonable iterator with specific characteristics, tailored for use with the `syn` crate.
81  ///
82  /// The `IterTrait` trait is designed to represent iterators that may yield references to items ( `&'a T` ) within the `syn` crate.
83  /// These iterators must also implement the `ExactSizeIterator`, `DoubleEndedIterator`, and `Clone` traits.
84  /// This combination ensures that the iterator can :
85  /// - Provide an exact size hint ( `ExactSizeIterator` ),
86  /// - Be traversed from both ends ( `DoubleEndedIterator` ),
87  /// - Be clonable ( `Clone` ).
88  ///
89  #[ cfg( feature = "iter_trait" ) ]
90  pub trait IterTrait< 'a, T >
91  where
92  T: 'a,
93  Self: _IterTrait< 'a, T > + Clone,
94  {
95 }
96
97  #[ cfg( feature = "iter_trait" ) ]
98  impl< 'a, T, I > IterTrait< 'a, T > for I
99  where
100  T: 'a,
101  Self: _IterTrait< 'a, T > + Clone,
102  {
103 }
104
105  /// Implement `Clone` for boxed `_IterTrait` trait objects.
106  ///
107  /// This allows cloning of boxed iterators that implement `_IterTrait`.
108  #[ cfg( feature = "iter_trait" ) ]
109  #[ cfg(any(not(feature = "no_std"), feature = "use_alloc")) ]
110  #[ allow( non_local_definitions ) ]
111  impl< 'c, T > Clone for Box< dyn _IterTrait<'c, T > + 'c> 
112{
113  #[ inline ]
114  fn clone( &self ) -> Self 
115  {
116   clone_dyn_types ::clone_into_box(&**self)
117 }
118 }
119
120  #[ cfg( feature = "iter_trait" ) ]
121  #[ cfg(any(not(feature = "no_std"), feature = "use_alloc")) ]
122  #[ allow( non_local_definitions ) ]
123  impl< 'c, T > Clone for Box< dyn _IterTrait<'c, T > + Send + 'c> 
124{
125  #[ inline ]
126  fn clone( &self ) -> Self 
127  {
128   clone_dyn_types ::clone_into_box(&**self)
129 }
130 }
131
132  #[ cfg( feature = "iter_trait" ) ]
133  #[ cfg(any(not(feature = "no_std"), feature = "use_alloc")) ]
134  #[ allow( non_local_definitions ) ]
135  impl< 'c, T > Clone for Box< dyn _IterTrait<'c, T > + Sync + 'c> 
136{
137  #[ inline ]
138  fn clone( &self ) -> Self 
139  {
140   clone_dyn_types ::clone_into_box(&**self)
141 }
142 }
143
144  #[ cfg( feature = "iter_trait" ) ]
145  #[ cfg(any(not(feature = "no_std"), feature = "use_alloc")) ]
146  #[ allow( non_local_definitions ) ]
147  impl< 'c, T > Clone for Box< dyn _IterTrait<'c, T > + Send + Sync + 'c> 
148{
149  #[ inline ]
150  fn clone( &self ) -> Self 
151  {
152   clone_dyn_types ::clone_into_box(&**self)
153 }
154 }
155
156  /// Type alias for boxed `_IterTrait` trait objects.
157  ///
158  /// Prefer `BoxedIter` over `impl _IterTrait` when using trait objects ( `dyn _IterTrait` ) because the concrete type in return is less restrictive than `impl _IterTrait`.
159  ///
160  #[ cfg( feature = "iter_trait" ) ]
161  #[ cfg(any(not(feature = "no_std"), feature = "use_alloc")) ]
162  pub type BoxedIter< 'a, T > = Box< dyn _IterTrait<'a, T > + 'a>;
163
164  /// Extension of iterator.
165  // zzz: review
166  #[ cfg( feature = "iter_ext" ) ]
167  #[ cfg(any(not(feature = "no_std"), feature = "use_alloc")) ]
168  pub trait IterExt
169  where
170  Self: core ::iter ::Iterator,
171  {
172  /// Iterate each element and return `core ::Result ::Err` if any element is error.
173  /// # Errors
174  /// qqq: errors
175  fn map_result< F, RE, El >(self, f: F) -> core ::result ::Result< Vec< El >, RE>
176  where
177   Self: Sized + Clone,
178   F: FnMut(< Self as core ::iter ::Iterator > ::Item) -> core ::result ::Result< El, RE >,
179   RE: core ::fmt ::Debug;
180 }
181
182  #[ cfg( feature = "iter_ext" ) ]
183  #[ cfg(any(not(feature = "no_std"), feature = "use_alloc")) ]
184  impl< Iterator > IterExt for Iterator
185  where
186  Iterator: core ::iter ::Iterator,
187  {
188  fn map_result< F, RE, El >(self, f: F) -> core ::result ::Result< Vec< El >, RE>
189  where
190   Self: Sized + Clone,
191   F: FnMut(< Self as core ::iter ::Iterator > ::Item) -> core ::result ::Result< El, RE >,
192   RE: core ::fmt ::Debug,
193  {
194   let vars_maybe = self.map(f);
195   let vars: Vec< _ > = ::itertools ::process_results(vars_maybe, |iter| iter.collect())?;
196   Ok(vars)
197 }
198 }
199}
200
201#[ doc( inline ) ]
202#[ allow( unused_imports ) ]
203pub use own :: *;
204
205/// Own namespace of the module.
206#[ allow( unused_imports ) ]
207pub mod own 
208{
209
210  use super :: *;
211  #[ doc( inline ) ]
212  pub use orphan :: *;
213}
214
215/// Orphan namespace of the module.
216#[ allow( unused_imports ) ]
217pub mod orphan 
218{
219
220  use super :: *;
221
222  #[ doc( inline ) ]
223  pub use exposed :: *;
224
225  #[ doc( inline ) ]
226  pub use ::itertools :: {
227  all,
228  any,
229  assert_equal,
230  chain,
231  cloned,
232  concat,
233  cons_tuples,
234  diff_with,
235  enumerate,
236  equal,
237  fold,
238  interleave,
239  intersperse,
240  intersperse_with,
241  iterate,
242  join,
243  kmerge,
244  kmerge_by,
245  max,
246  merge,
247  merge_join_by,
248  min,
249  multipeek,
250  multiunzip,
251  multizip,
252  partition,
253  peek_nth,
254  process_results,
255  put_back,
256  put_back_n,
257  rciter,
258  repeat_n,
259  rev,
260  sorted,
261  unfold,
262  // zip,
263  zip_eq,
264  Itertools,
265 };
266
267  #[ cfg(not(feature = "no_std")) ]
268  #[ doc( inline ) ]
269  pub use core ::iter ::zip;
270}
271
272/// Exposed namespace of the module.
273#[ allow( unused_imports ) ]
274pub mod exposed 
275{
276
277  use super :: *;
278
279  #[ doc( inline ) ]
280  pub use prelude :: *;
281
282  #[ doc( inline ) ]
283  #[ cfg( feature = "iter_trait" ) ]
284  pub use private :: { _IterTrait, IterTrait };
285
286  #[ doc( inline ) ]
287  #[ cfg( feature = "iter_trait" ) ]
288  #[ cfg(any(not(feature = "no_std"), feature = "use_alloc")) ]
289  pub use private ::BoxedIter;
290}
291
292/// Prelude to use essentials: `use my_module ::prelude :: *`.
293#[ allow( unused_imports ) ]
294pub mod prelude 
295{
296
297  use super :: *;
298
299  #[ doc( inline ) ]
300  pub use ::itertools :: { Diff, Either, EitherOrBoth, FoldWhile, MinMaxResult, Position, Itertools, PeekingNext };
301
302  #[ doc( inline ) ]
303  #[ cfg( feature = "iter_ext" ) ]
304  #[ cfg(any(not(feature = "no_std"), feature = "use_alloc")) ]
305  pub use private ::IterExt;
306}