Debian Codegraph @

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

raw symbols SCIP
1 use craterust-analyzer cargo itertools 0.14.0 crate/::size_hintrust-analyzer cargo itertools 0.14.0 size_hint/;
2 #[cfg(doc)]
3 use craterust-analyzer cargo itertools 0.14.0 crate/::Itertoolsrust-analyzer cargo itertools 0.14.0 Itertools#;
4 use craterust-analyzer cargo itertools 0.14.0 crate/::PeekingNextrust-analyzer cargo itertools 0.14.0 peeking_take_while/PeekingNext#;
5 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::collectionsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/::VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#;
6 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#;
7
8 /// See [`multipeek()`] for more information.
9 #[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:)]
10 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
11 pub struct MultiPeekrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#<I>
12 where
13 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
14 {
15 iterrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#iter.: Fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/Fuse#<I>,
16 bufrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#buf.: VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>,
17 indexrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#index.: usize,
18 }
19
20 /// An iterator adaptor that allows the user to peek at multiple `.next()`
21 /// values without advancing the base iterator.
22 ///
23 /// [`IntoIterator`] enabled version of [`Itertools::multipeek`].
24 pub fn multipeekrust-analyzer cargo itertools 0.14.0 multipeek_impl/multipeek().<I>(iterable: I) -> MultiPeekrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#<I::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter#>
25 where
26 I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#,
27 {
28 MultiPeekrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek# {
29 iterrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#iter.: iterable.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().().fuserust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fuse().(),
30 bufrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#buf.: VecDequerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/VecDeque#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T>`]new().(),
31 indexrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#index.: 0,
32 }
33 }
34
35 impl<I> MultiPeekrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#<I>
36 where
37 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
38 {
39 /// Reset the peeking “cursor”
40 pub fn reset_peekrust-analyzer cargo itertools 0.14.0 multipeek_impl/impl#[`MultiPeek<I>`]reset_peek().(&mut self) {
41 self.indexrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#index. = 0;
42 }
43 }
44
45 impl<I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#> MultiPeekrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#<I> {
46 /// Works exactly like `.next()` with the only difference that it doesn't
47 /// advance itself. `.peek()` can be called multiple times, to peek
48 /// further ahead.
49 /// When `.next()` is called, reset the peeking “cursor”.
50 pub fn peekrust-analyzer cargo itertools 0.14.0 multipeek_impl/impl#[`MultiPeek<I>`]peek().(&mut self) -> 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#> {
51 let ret = if self.indexrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#index. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.bufrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#buf..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]len().() {
52 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&self.bufrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#buf.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`][`Index<usize>`]index().self.indexrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#index.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`][`Index<usize>`]index().)
53 } else {
54 match self.iterrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]next().() {
55 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) => {
56 self.bufrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#buf..push_backrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]push_back().(x);
57 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&self.bufrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#buf.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`][`Index<usize>`]index().self.indexrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#index.]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`][`Index<usize>`]index().)
58 }
59 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
60 }
61 };
62
63 self.indexrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#index. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1;
64 ret
65 }
66 }
67
68 impl<I> PeekingNextrust-analyzer cargo itertools 0.14.0 peeking_take_while/PeekingNext# for MultiPeekrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#<I>
69 where
70 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
71 {
72 fn peeking_nextrust-analyzer cargo itertools 0.14.0 multipeek_impl/impl#[`MultiPeek<I>`][PeekingNext]peeking_next().<F>(&mut self, accept: F) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo itertools 0.14.0 multipeek_impl/impl#[`MultiPeek<I>`][PeekingNext]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>
73 where
74 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(&Selfrust-analyzer cargo itertools 0.14.0 multipeek_impl/impl#[`MultiPeek<I>`][PeekingNext]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> bool,
75 {
76 if self.bufrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#buf..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]is_empty().() {
77 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(r) = self.peekrust-analyzer cargo itertools 0.14.0 multipeek_impl/impl#[`MultiPeek<I>`]peek().() {
78 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().accept(r) {
79 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
80 }
81 }
82 } else if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(r) = self.bufrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#buf..frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]front().() {
83 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().accept(r) {
84 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
85 }
86 }
87 self.nextrust-analyzer cargo itertools 0.14.0 multipeek_impl/impl#[`MultiPeek<I>`][Iterator]next().()
88 }
89 }
90
91 impl<I> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for MultiPeekrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#<I>
92 where
93 I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#,
94 {
95 type Itemrust-analyzer cargo itertools 0.14.0 multipeek_impl/impl#[`MultiPeek<I>`][Iterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#;
96
97 fn nextrust-analyzer cargo itertools 0.14.0 multipeek_impl/impl#[`MultiPeek<I>`][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 multipeek_impl/impl#[`MultiPeek<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> {
98 self.indexrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#index. = 0;
99 self.bufrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#buf..pop_frontrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]pop_front().().or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or_else().(|| self.iterrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]next().())
100 }
101
102 fn size_hintrust-analyzer cargo itertools 0.14.0 multipeek_impl/impl#[`MultiPeek<I>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) {
103 size_hintrust-analyzer cargo itertools 0.14.0 size_hint/::add_scalarrust-analyzer cargo itertools 0.14.0 size_hint/add_scalar().(self.iterrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]size_hint().(), self.bufrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#buf..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`]len().())
104 }
105
106 fn foldrust-analyzer cargo itertools 0.14.0 multipeek_impl/impl#[`MultiPeek<I>`][Iterator]fold().<B, F>(self, mut init: B, mut f: F) -> B
107 where
108 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 multipeek_impl/impl#[`MultiPeek<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B,
109 {
110 init = self.bufrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#buf..into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/impl#[`VecDeque<T, A>`][IntoIterator]into_iter().().foldrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/vec_deque/into_iter/impl#[`IntoIter<T, A>`][Iterator]fold().(init, &mut f);
111 self.iterrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#iter..foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/fuse/impl#[`Fuse<I>`][Iterator]fold().(init, f)
112 }
113 }
114
115 // Same size
116 impl<I> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for MultiPeekrust-analyzer cargo itertools 0.14.0 multipeek_impl/MultiPeek#<I> where I: ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# {}