Maps supplied iterator and attempts to pair each `Ok(_)` item with an item from the slice which has provided index. Returns `Err` containing an invalid index in case slice length is exceeded.
(
iter: I,
pair_with: &'pairs [P],
)
| 12 | /// Maps supplied iterator and attempts to pair each `Ok(_)` item with an item from the slice which has provided index. |
| 13 | /// Returns `Err` containing an invalid index in case slice length is exceeded. |
| 14 | pub fn try_pair_with_slice<'iter, 'pairs, I, OK, E, P>( |
| 15 | iter: I, |
| 16 | pair_with: &'pairs [P], |
| 17 | ) -> impl Iterator<Item = Result<(&'pairs P, OK), E>> + 'iter |
| 18 | where |
| 19 | 'pairs: 'iter, |
| 20 | OK: 'iter, |
| 21 | I: IntoIterator<Item = Result<(usize, OK), E>> + 'iter, |
| 22 | E: From<IndexIsOutOfBounds>, |
| 23 | { |
| 24 | iter.into_iter().map(|indexed_item| { |
| 25 | let (index, item) = indexed_item?; |
| 26 | |
| 27 | let pair = pair_with.get(index).ok_or(IndexIsOutOfBounds { |
| 28 | index, |
| 29 | length: pair_with.len(), |
| 30 | })?; |
| 31 | |
| 32 | Ok((pair, item)) |
| 33 | }) |
| 34 | } |
| 35 | |
| 36 | /// Trait allowing to accumulatively validate supplied sequence of items. |
| 37 | pub trait SeqValidator<I> { |
no test coverage detected