icydb_base/validator/text/
mod.rs1pub mod case;
2pub mod color;
3
4use crate::{core::traits::Validator, prelude::*};
5
6#[validator]
13pub struct AlphaUscore {}
14
15impl Validator<str> for AlphaUscore {
16 fn validate(&self, s: &str) -> Result<(), String> {
17 if s.chars().all(|c| c.is_alphabetic() || c == '_') {
18 Ok(())
19 } else {
20 Err(format!("'{s}' is not alphabetic with underscores"))
21 }
22 }
23}
24
25#[validator]
30pub struct AlphanumUscore {}
31
32impl Validator<str> for AlphanumUscore {
33 fn validate(&self, s: &str) -> Result<(), String> {
34 if s.chars().all(|c| c.is_alphanumeric() || c == '_') {
35 Ok(())
36 } else {
37 Err(format!("'{s}' is not alphanumeric with underscores"))
38 }
39 }
40}
41
42#[validator]
47pub struct Ascii {}
48
49impl Validator<str> for Ascii {
50 fn validate(&self, s: &str) -> Result<(), String> {
51 if s.is_ascii() {
52 Ok(())
53 } else {
54 Err("string contains non-ascii characters".to_string())
55 }
56 }
57}