icydb/base/validator/text/
mod.rs1pub mod case;
2pub mod color;
3
4use crate::{design::prelude::*, traits::Validator};
5
6#[validator]
13pub struct AlphaUscore;
14
15impl Validator<str> for AlphaUscore {
16 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
17 if !s.chars().all(|c| c.is_alphabetic() || c == '_') {
18 ctx.issue(format!("'{s}' is not alphabetic with underscores"));
19 }
20 }
21}
22
23#[validator]
28pub struct AlphanumUscore;
29
30impl Validator<str> for AlphanumUscore {
31 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
32 if !s.chars().all(|c| c.is_alphanumeric() || c == '_') {
33 ctx.issue(format!("'{s}' is not alphanumeric with underscores"));
34 }
35 }
36}
37
38#[validator]
43pub struct Ascii;
44
45impl Validator<str> for Ascii {
46 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
47 if !s.is_ascii() {
48 ctx.issue("string contains non-ascii characters".to_string());
49 }
50 }
51}