zino-core 0.43.1

Core types and traits for zino.
Documentation
use super::Validator;
use crate::{bail, error::Error};

/// A validator for numeric characters.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct NumericValidator;

impl Validator<str> for NumericValidator {
    type Error = Error;

    #[inline]
    fn validate(&self, data: &str) -> Result<(), Self::Error> {
        for (index, ch) in data.char_indices() {
            if !ch.is_numeric() {
                bail!("char `{}` at the index `{}` is not numeric", ch, index);
            }
        }
        Ok(())
    }
}