| 1 | 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/::FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator#; |
| 2 | |
| 3 | /// An iterator that produces *n* repetitions of an element. |
| 4 | /// |
| 5 | /// See [`repeat_n()`](crate::repeat_n) for more information. |
| 6 | #[must_use = "iterators are lazy and do nothing unless consumed"] |
| 7 | #[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:)] |
| 8 | pub struct RepeatNrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#<A> { |
| 9 | pub(craterust-analyzer cargo itertools 0.14.0 crate/) eltrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#elt.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<A>, |
| 10 | nrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#n.: usize, |
| 11 | } |
| 12 | |
| 13 | /// Create an iterator that produces `n` repetitions of `element`. |
| 14 | pub fn repeat_nrust-analyzer cargo itertools 0.14.0 repeatn/repeat_n().<A>(element: A, n: usize) -> RepeatNrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#<A> |
| 15 | where |
| 16 | A: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 17 | { |
| 18 | if n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 19 | RepeatNrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN# { eltrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#elt.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, nrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#n. } |
| 20 | } else { |
| 21 | RepeatNrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN# { |
| 22 | eltrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#elt.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(element), |
| 23 | nrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#n., |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | impl<A> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for RepeatNrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#<A> |
| 29 | where |
| 30 | A: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 31 | { |
| 32 | type Itemrust-analyzer cargo itertools 0.14.0 repeatn/impl#[`RepeatN<A>`][Iterator]Item# = A; |
| 33 | |
| 34 | fn nextrust-analyzer cargo itertools 0.14.0 repeatn/impl#[`RepeatN<A>`][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 repeatn/impl#[`RepeatN<A>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 35 | if self.nrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#n. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().1 { |
| 36 | self.nrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#n. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1; |
| 37 | self.eltrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#elt..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().() |
| 38 | } else { |
| 39 | self.nrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#n. = 0; |
| 40 | self.eltrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#elt..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | fn size_hintrust-analyzer cargo itertools 0.14.0 repeatn/impl#[`RepeatN<A>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 45 | (self.nrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#n., Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.nrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#n.)) |
| 46 | } |
| 47 | |
| 48 | fn foldrust-analyzer cargo itertools 0.14.0 repeatn/impl#[`RepeatN<A>`][Iterator]fold().<B, F>(self, mut init: B, mut f: F) -> B |
| 49 | where |
| 50 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 repeatn/impl#[`RepeatN<A>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B, |
| 51 | { |
| 52 | match self { |
| 53 | Selfrust-analyzer cargo itertools 0.14.0 repeatn/impl#[`RepeatN<A>`][Iterator] { eltrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#elt.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(elt), nrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#n. } => { |
| 54 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(n >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). 0); |
| 55 | init = (1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#n).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|_| elt.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()).foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]fold().(init, &mut f); |
| 56 | f(init, elt) |
| 57 | } |
| 58 | _ => init, |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | impl<A> DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator# for RepeatNrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#<A> |
| 64 | where |
| 65 | A: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 66 | { |
| 67 | #[inline] |
| 68 | fn next_backrust-analyzer cargo itertools 0.14.0 repeatn/impl#[`RepeatN<A>`][DoubleEndedIterator]next_back().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo itertools 0.14.0 repeatn/impl#[`RepeatN<A>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 69 | self.nextrust-analyzer cargo itertools 0.14.0 repeatn/impl#[`RepeatN<A>`][Iterator]next().() |
| 70 | } |
| 71 | |
| 72 | #[inline] |
| 73 | fn rfoldrust-analyzer cargo itertools 0.14.0 repeatn/impl#[`RepeatN<A>`][DoubleEndedIterator]rfold().<B, F>(self, init: B, f: F) -> B |
| 74 | where |
| 75 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 repeatn/impl#[`RepeatN<A>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B, |
| 76 | { |
| 77 | self.foldrust-analyzer cargo itertools 0.14.0 repeatn/impl#[`RepeatN<A>`][Iterator]fold().(init, f) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | impl<A> ExactSizeIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/exact_size/ExactSizeIterator# for RepeatNrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#<A> where A: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# {} |
| 82 | |
| 83 | impl<A> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for RepeatNrust-analyzer cargo itertools 0.14.0 repeatn/RepeatN#<A> where A: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone# {} |