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

Function try_validate

utils/src/try_iter.rs:157–172  ·  view source on GitHub ↗

Ensures that the given iterator satisfies provided validator for each successful item. In case of an error, `Err(E)` will be emitted.

(iter: I, mut validator: V)

Source from the content-addressed store, hash-verified

155/// Ensures that the given iterator satisfies provided validator for each successful item.
156/// In case of an error, `Err(E)` will be emitted.
157pub fn try_validate<I, OK, E, V>(iter: I, mut validator: V) -> impl Iterator<Item = Result<OK, E>>
158where
159 I: IntoIterator<Item = Result<OK, E>>,
160 V: SeqValidator<OK>,
161 E: From<V::Failure>,
162{
163 iter.into_iter().map(move |res| {
164 let item = res?;
165
166 if let Some(failure) = validator.validate(&item) {
167 Err(failure.into())
168 } else {
169 Ok(item)
170 }
171 })
172}

Callers 1

validateFunction · 0.85

Calls 3

mapMethod · 0.80
into_iterMethod · 0.45
validateMethod · 0.45

Tested by

no test coverage detected