Skip to main content

macro_tools/
iter.rs

1//!
2//! Tailored iterator.
3//!
4
5/// Define a private namespace for all its items.
6mod private
7{
8  use ::clone_dyn_types ::CloneDyn;
9
10  /// Trait that encapsulates an iterator with specific characteristics implementing `CloneDyn`.
11  ///
12  /// Represents iterators that yield references to items `&'a T`, also implementing
13  /// `ExactSizeIterator`, `DoubleEndedIterator`, and `CloneDyn`.
14  pub trait _IterTrait< 'a, T >
15  where
16  T : 'a,
17  Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator,
18  Self : CloneDyn,
19  {
20  }
21
22  impl< 'a, T, I > _IterTrait< 'a, T > for I
23  where
24  T : 'a,
25  Self : Iterator< Item = T > + ExactSizeIterator< Item = T > + DoubleEndedIterator,
26  Self : CloneDyn,
27  {
28  }
29
30  /// Trait that encapsulates a clonable iterator with specific characteristics.
31  pub trait IterTrait< 'a, T >
32  where
33  T : 'a,
34  Self : _IterTrait< 'a, T > + Clone,
35  {
36  }
37
38  impl< 'a, T, I > IterTrait< 'a, T > for I
39  where
40  T : 'a,
41  Self : _IterTrait< 'a, T > + Clone,
42  {
43  }
44
45  /// Implement `Clone` for boxed `_IterTrait` trait objects.
46  #[ allow( non_local_definitions ) ]
47  impl< 'c, T > Clone for Box< dyn _IterTrait< 'c, T > + 'c >
48  {
49    #[ inline ]
50    fn clone( &self ) -> Self
51    {
52      ::clone_dyn_types ::clone_into_box( &**self )
53    }
54  }
55
56  #[ allow( non_local_definitions ) ]
57  impl< 'c, T > Clone for Box< dyn _IterTrait< 'c, T > + Send + 'c >
58  {
59    #[ inline ]
60    fn clone( &self ) -> Self
61    {
62      ::clone_dyn_types ::clone_into_box( &**self )
63    }
64  }
65
66  #[ allow( non_local_definitions ) ]
67  impl< 'c, T > Clone for Box< dyn _IterTrait< 'c, T > + Sync + 'c >
68  {
69    #[ inline ]
70    fn clone( &self ) -> Self
71    {
72      ::clone_dyn_types ::clone_into_box( &**self )
73    }
74  }
75
76  #[ allow( non_local_definitions ) ]
77  impl< 'c, T > Clone for Box< dyn _IterTrait< 'c, T > + Send + Sync + 'c >
78  {
79    #[ inline ]
80    fn clone( &self ) -> Self
81    {
82      ::clone_dyn_types ::clone_into_box( &**self )
83    }
84  }
85
86  /// Type alias for boxed `_IterTrait` trait objects.
87  ///
88  /// Prefer `BoxedIter` over `impl _IterTrait` when using trait objects (`dyn _IterTrait`)
89  /// because the concrete type in return is less restrictive than `impl _IterTrait`.
90  pub type BoxedIter< 'a, T > = Box< dyn _IterTrait< 'a, T > + 'a >;
91}
92
93#[ doc( inline ) ]
94#[ allow( unused_imports ) ]
95pub use own :: *;
96
97/// Own namespace of the module.
98#[ allow( unused_imports ) ]
99pub mod own
100{
101  use super :: *;
102  #[ doc( inline ) ]
103  pub use orphan :: *;
104}
105
106/// Orphan namespace of the module.
107#[ allow( unused_imports ) ]
108pub mod orphan
109{
110  use super :: *;
111
112  #[ doc( inline ) ]
113  pub use exposed :: *;
114
115  #[ doc( inline ) ]
116  pub use ::itertools ::
117  {
118    all,
119    any,
120    assert_equal,
121    chain,
122    cloned,
123    concat,
124    cons_tuples,
125    diff_with,
126    enumerate,
127    equal,
128    fold,
129    interleave,
130    intersperse,
131    intersperse_with,
132    iterate,
133    join,
134    kmerge,
135    kmerge_by,
136    max,
137    merge,
138    merge_join_by,
139    min,
140    multipeek,
141    multiunzip,
142    multizip,
143    partition,
144    peek_nth,
145    process_results,
146    put_back,
147    put_back_n,
148    rciter,
149    repeat_n,
150    rev,
151    sorted,
152    // zip,
153    zip_eq,
154    Itertools,
155  };
156
157  #[ doc( inline ) ]
158  pub use core ::iter ::zip;
159}
160
161/// Exposed namespace of the module.
162#[ allow( unused_imports ) ]
163pub mod exposed
164{
165  use super :: *;
166
167  #[ doc( inline ) ]
168  pub use prelude :: *;
169
170  #[ doc( inline ) ]
171  pub use private :: { _IterTrait, IterTrait };
172
173  #[ doc( inline ) ]
174  pub use private ::BoxedIter;
175}
176
177/// Prelude to use essentials: `use my_module::prelude::*`.
178#[ allow( unused_imports ) ]
179pub mod prelude
180{
181  use super :: *;
182
183  #[ doc( inline ) ]
184  pub use ::itertools :: { Diff, Either, EitherOrBoth, FoldWhile, MinMaxResult, Position, Itertools, PeekingNext };
185}