icydb_model/base/validator/text/
mod.rs1pub mod case;
8pub mod color;
9
10use crate::{prelude::*, visitor::Validator};
11
12#[validator]
19pub struct AlphaUscore;
20
21impl Validator<str> for AlphaUscore {
22 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
23 if !s.chars().all(|c| c.is_alphabetic() || c == '_') {
24 ctx.issue("text must be alphabetic or underscore");
25 }
26 }
27}
28
29#[validator]
34pub struct AlphanumUscore;
35
36impl Validator<str> for AlphanumUscore {
37 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
38 if !s.chars().all(|c| c.is_alphanumeric() || c == '_') {
39 ctx.issue("text must be alphanumeric or underscore");
40 }
41 }
42}
43
44#[validator]
49pub struct Ascii;
50
51impl Validator<str> for Ascii {
52 fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
53 if !s.is_ascii() {
54 ctx.issue("text must be ASCII");
55 }
56 }
57}