zino_core/validation/validator/
alphanumeric.rs1use super::Validator;
2use crate::{bail, error::Error};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub struct AlphanumericValidator;
7
8impl Validator<str> for AlphanumericValidator {
9 type Error = Error;
10
11 #[inline]
12 fn validate(&self, data: &str) -> Result<(), Self::Error> {
13 for (index, ch) in data.char_indices() {
14 if !ch.is_alphanumeric() {
15 bail!("char `{}` at the index `{}` is not alphanumeric", ch, index);
16 }
17 }
18 Ok(())
19 }
20}