zino_core/validation/validator/
ascii_hexdigit.rs

1use super::Validator;
2use crate::{bail, error::Error};
3
4/// A validator for ASCII hexadecimal digits.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub struct AsciiHexdigitValidator;
7
8impl Validator<str> for AsciiHexdigitValidator {
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_ascii_hexdigit() {
15                bail!(
16                    "char `{}` at the index `{}` is not an ASCII hexadecimal digit",
17                    ch,
18                    index
19                );
20            }
21        }
22        Ok(())
23    }
24}