Debian Codegraph @

debian/missing-sources/itertools/src/intersperse.rs

raw symbols SCIP
1 use superrust-analyzer cargo itertools 0.14.0 crate/::size_hintrust-analyzer cargo itertools 0.14.0 size_hint/;
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::{Fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/Fuse#, FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#};
3
4 pub trait IntersperseElementrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElement#<Item> {
5 fn generaterust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElement#generate().(&mut self) -> Item;
6 }
7
8 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
9 pub struct IntersperseElementSimplerust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElementSimple#<Item>(Item);
10
11 impl<Item: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#> IntersperseElementrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElement#<Item> for IntersperseElementSimplerust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElementSimple#<Item> {
12 fn generaterust-analyzer cargo itertools 0.14.0 intersperse/impl#[`IntersperseElementSimple<Item>`][`IntersperseElement<Item>`]generate().(&mut self) -> Item {
13 self.0rust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElementSimple#0..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()
14 }
15 }
16
17 /// An iterator adaptor to insert a particular value
18 /// between each element of the adapted iterator.
19 ///
20 /// Iterator element type is `I::Item`
21 ///
22 /// This iterator is *fused*.
23 ///
24 /// See [`.intersperse()`](crate::Itertools::intersperse) for more information.
25 pub type Intersperserust-analyzer cargo itertools 0.14.0 intersperse/Intersperse#<I> = IntersperseWithrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#<I, IntersperseElementSimplerust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElementSimple#<<I as Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#>::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>>;
26
27 /// Create a new Intersperse iterator
28 pub fn intersperserust-analyzer cargo itertools 0.14.0 intersperse/intersperse().<I>(iter: I, elt: I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> Intersperserust-analyzer cargo itertools 0.14.0 intersperse/Intersperse#<I>
29 where
30 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
31 {
32 intersperse_withrust-analyzer cargo itertools 0.14.0 intersperse/intersperse_with().(iter, IntersperseElementSimplerust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElementSimple#(elt))
33 }
34
35 impl<Item, F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#() -> Item> IntersperseElementrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElement#<Item> for F {
36 fn generaterust-analyzer cargo itertools 0.14.0 intersperse/impl#[F][`IntersperseElement<Item>`]generate().(&mut self) -> Item {
37 self()
38 }
39 }
40
41 /// An iterator adaptor to insert a particular value created by a function
42 /// between each element of the adapted iterator.
43 ///
44 /// Iterator element type is `I::Item`
45 ///
46 /// This iterator is *fused*.
47 ///
48 /// See [`.intersperse_with()`](crate::Itertools::intersperse_with) for more information.
49 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
50 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
51 pub struct IntersperseWithrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#<I, ElemF>
52 where
53 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
54 {
55 elementrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#element.: ElemF,
56 iterrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#iter.: Fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/Fuse#<I>,
57 /// `peek` is None while no item have been taken out of `iter` (at definition).
58 /// Then `peek` will alternatively be `Some(None)` and `Some(Some(item))`,
59 /// where `None` indicates it's time to generate from `element` (unless `iter` is empty).
60 peekrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#peek.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>>,
61 }
62
63 /// Create a new `IntersperseWith` iterator
64 pub fn intersperse_withrust-analyzer cargo itertools 0.14.0 intersperse/intersperse_with().<I, ElemF>(iter: I, elt: ElemF) -> IntersperseWithrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#<I, ElemF>
65 where
66 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
67 {
68 IntersperseWithrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith# {
69 peekrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#peek.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
70 iterrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#iter.: iter.fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fuse().(),
71 elementrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#element.: elt,
72 }
73 }
74
75 impl<I, ElemF> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for IntersperseWithrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#<I, ElemF>
76 where
77 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
78 ElemF: IntersperseElementrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElement#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>,
79 {
80 type Itemrust-analyzer cargo itertools 0.14.0 intersperse/impl#[`IntersperseWith<I, ElemF>`][Iterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#;
81 #[inline]
82 fn nextrust-analyzer cargo itertools 0.14.0 intersperse/impl#[`IntersperseWith<I, ElemF>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo itertools 0.14.0 intersperse/impl#[`IntersperseWith<I, ElemF>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
83 let Selfrust-analyzer cargo itertools 0.14.0 intersperse/impl#[`IntersperseWith<I, ElemF>`][Iterator] {
84 elementrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#element.,
85 iterrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#iter.,
86 peekrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#peek.,
87 } = self;
88 match peek {
89 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(item @ Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_)) => item.takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().(),
90 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => match iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]next().() {
91 new @ Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => {
92 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().peek = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(new);
93 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(element.generaterust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElement#generate().())
94 }
95 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
96 },
97 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
98 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().peek = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#);
99 iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]next().()
100 }
101 }
102 }
103
104 fn size_hintrust-analyzer cargo itertools 0.14.0 intersperse/impl#[`IntersperseWith<I, ElemF>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
105 let mut sh = self.iterrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]size_hint().();
106 sh = size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::addrust-analyzer cargo itertools 0.14.0 size_hint/add().(sh, sh);
107 match self.peekrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#peek. {
108 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_)) => size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::add_scalarrust-analyzer cargo itertools 0.14.0 size_hint/add_scalar().(sh, 1),
109 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => sh,
110 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::sub_scalarrust-analyzer cargo itertools 0.14.0 size_hint/sub_scalar().(sh, 1),
111 }
112 }
113
114 fn foldrust-analyzer cargo itertools 0.14.0 intersperse/impl#[`IntersperseWith<I, ElemF>`][Iterator]fold().<B, F>(self, init: B, mut f: F) -> B
115 where
116 Selfrust-analyzer cargo itertools 0.14.0 intersperse/impl#[`IntersperseWith<I, ElemF>`][Iterator]: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#,
117 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 intersperse/impl#[`IntersperseWith<I, ElemF>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B,
118 {
119 let Selfrust-analyzer cargo itertools 0.14.0 intersperse/impl#[`IntersperseWith<I, ElemF>`][Iterator] {
120 mut elementrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#element.,
121 mut iterrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#iter.,
122 peekrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#peek.,
123 } = self;
124 let mut accum = init;
125
126 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) = peek.unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| iter.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]next().()) {
127 accum = f(accum, x);
128 }
129
130 iter.foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]fold().(accum, |accum, x| {
131 let accum = f(accum, element.generaterust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElement#generate().());
132 f(accum, x)
133 })
134 }
135 }
136
137 impl<I, ElemF> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for IntersperseWithrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseWith#<I, ElemF>
138 where
139 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
140 ElemF: IntersperseElementrust-analyzer cargo itertools 0.14.0 intersperse/IntersperseElement#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>,
141 {
142 }