| 1 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#; |
| 2 | |
| 3 | use craterust-analyzer cargo itertools 0.14.0 crate/::size_hintrust-analyzer cargo itertools 0.14.0 size_hint/; |
| 4 | |
| 5 | /// An iterator adaptor that allows putting multiple |
| 6 | /// items in front of the iterator. |
| 7 | /// |
| 8 | /// Iterator element type is `I::Item`. |
| 9 | #[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:)] |
| 10 | #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] |
| 11 | pub struct PutBackNrust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#<I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#> { |
| 12 | toprust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#top.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#>, |
| 13 | iterrust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#iter.: I, |
| 14 | } |
| 15 | |
| 16 | /// Create an iterator where you can put back multiple values to the front |
| 17 | /// of the iteration. |
| 18 | /// |
| 19 | /// Iterator element type is `I::Item`. |
| 20 | pub fn put_back_nrust-analyzer cargo itertools 0.14.0 put_back_n_impl/put_back_n().<I>(iterable: I) -> PutBackNrust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#<I::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter#> |
| 21 | where |
| 22 | I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#, |
| 23 | { |
| 24 | PutBackNrust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN# { |
| 25 | toprust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#top.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 26 | iterrust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#iter.: iterable.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().(), |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | impl<I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#> PutBackNrust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#<I> { |
| 31 | /// Puts `x` in front of the iterator. |
| 32 | /// |
| 33 | /// The values are yielded in order of the most recently put back |
| 34 | /// values first. |
| 35 | /// |
| 36 | /// ```rust |
| 37 | /// use itertools::put_back_n; |
| 38 | /// |
| 39 | /// let mut it = put_back_n(1..5); |
| 40 | /// it.next(); |
| 41 | /// it.put_back(1); |
| 42 | /// it.put_back(0); |
| 43 | /// |
| 44 | /// assert!(itertools::equal(it, 0..5)); |
| 45 | /// ``` |
| 46 | #[inline] |
| 47 | pub fn put_backrust-analyzer cargo itertools 0.14.0 put_back_n_impl/impl#[`PutBackN<I>`]put_back().(&mut self, x: I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) { |
| 48 | self.toprust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#top..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(x); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | impl<I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for PutBackNrust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#<I> { |
| 53 | type Itemrust-analyzer cargo itertools 0.14.0 put_back_n_impl/impl#[`PutBackN<I>`][Iterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#; |
| 54 | #[inline] |
| 55 | fn nextrust-analyzer cargo itertools 0.14.0 put_back_n_impl/impl#[`PutBackN<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 put_back_n_impl/impl#[`PutBackN<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 56 | self.toprust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#top..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().().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 put_back_n_impl/PutBackN#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().()) |
| 57 | } |
| 58 | |
| 59 | #[inline] |
| 60 | fn size_hintrust-analyzer cargo itertools 0.14.0 put_back_n_impl/impl#[`PutBackN<I>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 61 | 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 put_back_n_impl/PutBackN#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(), self.toprust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#top..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()) |
| 62 | } |
| 63 | |
| 64 | fn foldrust-analyzer cargo itertools 0.14.0 put_back_n_impl/impl#[`PutBackN<I>`][Iterator]fold().<B, F>(self, mut init: B, mut f: F) -> B |
| 65 | where |
| 66 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 put_back_n_impl/impl#[`PutBackN<I>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B, |
| 67 | { |
| 68 | init = self.toprust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#top..into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().rfoldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#rfold().(init, &mut f); |
| 69 | self.iterrust-analyzer cargo itertools 0.14.0 put_back_n_impl/PutBackN#iter..foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#fold().(init, f) |
| 70 | } |
| 71 | } |