| 1 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core 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 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/; |
| 3 | |
| 4 | /// An iterator adaptor that consumes elements while the given predicate is |
| 5 | /// `true`, including the element for which the predicate first returned |
| 6 | /// `false`. |
| 7 | /// |
| 8 | /// See [`.take_while_inclusive()`](crate::Itertools::take_while_inclusive) |
| 9 | /// for more information. |
| 10 | #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] |
| 11 | #[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:)] |
| 12 | pub struct TakeWhileInclusiverust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#<I, F> { |
| 13 | iterrust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#iter.: I, |
| 14 | predicaterust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#predicate.: F, |
| 15 | donerust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#done.: bool, |
| 16 | } |
| 17 | |
| 18 | impl<I, F> TakeWhileInclusiverust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#<I, F> |
| 19 | where |
| 20 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 21 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> bool, |
| 22 | { |
| 23 | /// Create a new [`TakeWhileInclusive`] from an iterator and a predicate. |
| 24 | pub(craterust-analyzer cargo itertools 0.14.0 crate/) fn newrust-analyzer cargo itertools 0.14.0 take_while_inclusive/impl#[`TakeWhileInclusive<I, F>`]new().(iter: I, predicate: F) -> Selfrust-analyzer cargo itertools 0.14.0 take_while_inclusive/impl#[`TakeWhileInclusive<I, F>`] { |
| 25 | Selfrust-analyzer cargo itertools 0.14.0 take_while_inclusive/impl#[`TakeWhileInclusive<I, F>`] { |
| 26 | iterrust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#iter., |
| 27 | predicaterust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#predicate., |
| 28 | donerust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#done.: false, |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | impl<I, F> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for TakeWhileInclusiverust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#<I, F> |
| 34 | where |
| 35 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# + fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, |
| 36 | { |
| 37 | debug_fmt_fieldsrust-analyzer cargo itertools 0.14.0 impl_macros/debug_fmt_fields!!(TakeWhileInclusive, iterrust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#iter., donerust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#done.); |
| 38 | } |
| 39 | |
| 40 | impl<I, F> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for TakeWhileInclusiverust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#<I, F> |
| 41 | where |
| 42 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 43 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> bool, |
| 44 | { |
| 45 | type Itemrust-analyzer cargo itertools 0.14.0 take_while_inclusive/impl#[`TakeWhileInclusive<I, F>`][Iterator]Item# = I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#; |
| 46 | |
| 47 | fn nextrust-analyzer cargo itertools 0.14.0 take_while_inclusive/impl#[`TakeWhileInclusive<I, F>`][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 take_while_inclusive/impl#[`TakeWhileInclusive<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 48 | if self.donerust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#done. { |
| 49 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 50 | } else { |
| 51 | self.iterrust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|item| { |
| 52 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(self.predicaterust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#predicate.)(&item) { |
| 53 | self.donerust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#done. = true; |
| 54 | } |
| 55 | item |
| 56 | }) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | fn size_hintrust-analyzer cargo itertools 0.14.0 take_while_inclusive/impl#[`TakeWhileInclusive<I, F>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 61 | if self.donerust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#done. { |
| 62 | (0, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(0)) |
| 63 | } else { |
| 64 | (0, self.iterrust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().().1) |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | fn foldrust-analyzer cargo itertools 0.14.0 take_while_inclusive/impl#[`TakeWhileInclusive<I, F>`][Iterator]fold().<B, Fold>(mut self, init: B, mut f: Fold) -> B |
| 69 | where |
| 70 | Fold: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 take_while_inclusive/impl#[`TakeWhileInclusive<I, F>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B, |
| 71 | { |
| 72 | if self.donerust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#done. { |
| 73 | init |
| 74 | } else { |
| 75 | let predicate = &mut self.predicaterust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#predicate.; |
| 76 | self.iterrust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#iter. |
| 77 | .try_foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#try_fold().(init, |mut acc, item| { |
| 78 | let is_ok = predicate(&item); |
| 79 | acc = f(acc, item); |
| 80 | if is_ok { |
| 81 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(acc) |
| 82 | } else { |
| 83 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(acc) |
| 84 | } |
| 85 | }) |
| 86 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|err| err) |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | impl<I, F> FusedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/marker/FusedIterator# for TakeWhileInclusiverust-analyzer cargo itertools 0.14.0 take_while_inclusive/TakeWhileInclusive#<I, F> |
| 92 | where |
| 93 | I: Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#, |
| 94 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> bool, |
| 95 | { |
| 96 | } |