| 1 | #[cfg(doc)] |
| 2 | use craterust-analyzer cargo itertools 0.14.0 crate/::Itertoolsrust-analyzer cargo itertools 0.14.0 Itertools#; |
| 3 | |
| 4 | /// An iterator that produces only the `T` values as long as the |
| 5 | /// inner iterator produces `Ok(T)`. |
| 6 | /// |
| 7 | /// Used by [`process_results`](crate::process_results), see its docs |
| 8 | /// for more information. |
| 9 | #[must_use = "iterator adaptors are lazy and do nothing unless consumed"] |
| 10 | #[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:)] |
| 11 | pub struct ProcessResultsrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#<'a, I, E: 'a> { |
| 12 | errorrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#error.: &'a mut Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), E>, |
| 13 | iterrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#iter.: I, |
| 14 | } |
| 15 | |
| 16 | impl<I, E> ProcessResultsrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#<'_, I, E> { |
| 17 | #[inline(always)] |
| 18 | fn next_bodyrust-analyzer cargo itertools 0.14.0 process_results_impl/impl#[`ProcessResults<'_, I, E>`]next_body().<T>(&mut self, item: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<T> { |
| 19 | match item { |
| 20 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(x)) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x), |
| 21 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e)) => { |
| 22 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self.errorrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#error. = Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e); |
| 23 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 24 | } |
| 25 | 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#, |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | impl<I, T, E> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for ProcessResultsrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#<'_, I, E> |
| 31 | where |
| 32 | I: 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# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>, |
| 33 | { |
| 34 | type Itemrust-analyzer cargo itertools 0.14.0 process_results_impl/impl#[`ProcessResults<'_, I, E>`][Iterator]Item# = T; |
| 35 | |
| 36 | fn nextrust-analyzer cargo itertools 0.14.0 process_results_impl/impl#[`ProcessResults<'_, I, E>`][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 process_results_impl/impl#[`ProcessResults<'_, I, E>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 37 | let item = self.iterrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#iter..nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().(); |
| 38 | self.next_bodyrust-analyzer cargo itertools 0.14.0 process_results_impl/impl#[`ProcessResults<'_, I, E>`]next_body().(item) |
| 39 | } |
| 40 | |
| 41 | fn size_hintrust-analyzer cargo itertools 0.14.0 process_results_impl/impl#[`ProcessResults<'_, I, E>`][Iterator]size_hint().(&self) -> (usize, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<usize>) { |
| 42 | (0, self.iterrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#iter..size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().().1) |
| 43 | } |
| 44 | |
| 45 | fn foldrust-analyzer cargo itertools 0.14.0 process_results_impl/impl#[`ProcessResults<'_, I, E>`][Iterator]fold().<B, F>(mut self, init: B, mut f: F) -> B |
| 46 | where |
| 47 | Selfrust-analyzer cargo itertools 0.14.0 process_results_impl/impl#[`ProcessResults<'_, I, E>`][Iterator]: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 48 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(B, Selfrust-analyzer cargo itertools 0.14.0 process_results_impl/impl#[`ProcessResults<'_, I, E>`][Iterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B, |
| 49 | { |
| 50 | let error = self.errorrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#error.; |
| 51 | self.iterrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#iter. |
| 52 | .try_foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#try_fold().(init, |acc, opt| match opt { |
| 53 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(x) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(f(acc, x)), |
| 54 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => { |
| 55 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().error = Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e); |
| 56 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(acc) |
| 57 | } |
| 58 | }) |
| 59 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|e| e) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | impl<I, T, E> DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator# for ProcessResultsrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#<'_, I, E> |
| 64 | where |
| 65 | I: 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# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>, |
| 66 | I: DoubleEndedIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#, |
| 67 | { |
| 68 | fn next_backrust-analyzer cargo itertools 0.14.0 process_results_impl/impl#[`ProcessResults<'_, I, E>`][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 process_results_impl/impl#[`ProcessResults<'_, I, E>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#> { |
| 69 | let item = self.iterrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#iter..next_backrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#next_back().(); |
| 70 | self.next_bodyrust-analyzer cargo itertools 0.14.0 process_results_impl/impl#[`ProcessResults<'_, I, E>`]next_body().(item) |
| 71 | } |
| 72 | |
| 73 | fn rfoldrust-analyzer cargo itertools 0.14.0 process_results_impl/impl#[`ProcessResults<'_, I, E>`][DoubleEndedIterator]rfold().<B, F>(mut self, init: B, mut 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 process_results_impl/impl#[`ProcessResults<'_, I, E>`][DoubleEndedIterator]::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item#) -> B, |
| 76 | { |
| 77 | let error = self.errorrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#error.; |
| 78 | self.iterrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#iter. |
| 79 | .try_rfoldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/double_ended/DoubleEndedIterator#try_rfold().(init, |acc, opt| match opt { |
| 80 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(x) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(f(acc, x)), |
| 81 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => { |
| 82 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().error = Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e); |
| 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().(|e| e) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /// “Lift” a function of the values of an iterator so that it can process |
| 91 | /// an iterator of `Result` values instead. |
| 92 | /// |
| 93 | /// [`IntoIterator`] enabled version of [`Itertools::process_results`]. |
| 94 | pub fn process_resultsrust-analyzer cargo itertools 0.14.0 process_results_impl/process_results().<I, F, T, E, R>(iterable: I, processor: F) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<R, E> |
| 95 | where |
| 96 | I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, E>>, |
| 97 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(ProcessResultsrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#<I::IntoIterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#IntoIter#, E>) -> R, |
| 98 | { |
| 99 | let iter = iterable.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().(); |
| 100 | let mut error = Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 101 | |
| 102 | let result = processor(ProcessResultsrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults# { |
| 103 | errorrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#error.: &mut error, |
| 104 | iterrust-analyzer cargo itertools 0.14.0 process_results_impl/ProcessResults#iter., |
| 105 | }); |
| 106 | |
| 107 | error.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|_| result) |
| 108 | } |