Skip to main content

validate_batch

Function validate_batch 

Source
pub fn validate_batch<T: KeyDomain, I>(
    keys: I,
) -> (Vec<String>, Vec<(String, KeyParseError)>)
where I: IntoIterator, I::Item: AsRef<str>,
Expand description

Validate multiple keys at once

This function validates a collection of keys and returns which ones are valid and which ones failed validation.

§Arguments

  • keys - Iterator of string-like items to validate

§Returns

A tuple containing:

  • Vector of valid key strings
  • Vector of (invalid key string, error) pairs

§Examples

use domain_key::{Domain, KeyDomain, validation};

#[derive(Debug)]
struct TestDomain;
impl Domain for TestDomain {
    const DOMAIN_NAME: &'static str = "test";
}
impl KeyDomain for TestDomain {}

let keys = vec!["valid_key", "", "another_valid", "bad key"];
let (valid, invalid) = validation::validate_batch::<TestDomain, _>(keys);

assert_eq!(valid.len(), 2);
assert_eq!(invalid.len(), 2);