zino_core/validation/validator/uppercase.rs
1use super::Validator;
2use crate::{bail, error::Error};
3
4/// A validator for uppercase characters.
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub struct UppercaseValidator;
7
8impl Validator<str> for UppercaseValidator {
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_uppercase() {
15 bail!("char `{}` at the index `{}` is not uppercase", ch, index);
16 }
17 }
18 Ok(())
19 }
20}