MCPcopy Create free account
hub / github.com/docknetwork/crypto / try_pair_with_slice

Function try_pair_with_slice

utils/src/try_iter.rs:14–34  ·  view source on GitHub ↗

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],
)

Source from the content-addressed store, hash-verified

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.
14pub 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
18where
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.
37pub trait SeqValidator<I> {

Callers 2

pair_with_sliceFunction · 0.85

Calls 4

mapMethod · 0.80
getMethod · 0.80
into_iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected