Skip to main content

icydb_model/base/normalizer/text/
ascii.rs

1//! Module: base::normalizer::text::ascii
2//!
3//! Responsibility: base normalizer definitions.
4//! Does not own: validation policy, persistence, or schema mutation semantics.
5//! Boundary: mutates schema field values through facade normalizer traits.
6
7use crate::{prelude::*, visitor::Normalizer};
8
9///
10/// AlphaNumeric
11///
12/// Removes any non-alphanumeric characters from the input string.
13/// Keeps only ASCII digits 0–9, A–Z, a–z
14///
15
16#[normalizer]
17pub struct AlphaNumeric;
18
19impl Normalizer<String> for AlphaNumeric {
20    fn normalize(&self, value: &mut String) -> Result<(), String> {
21        // Retain only ASCII alphanumeric characters
22        value.retain(|c| c.is_ascii_alphanumeric());
23
24        Ok(())
25    }
26}
27
28///
29/// Numeric
30///
31/// Removes any non-numeric characters from the input string.
32/// Keeps only ASCII digits 0–9.
33///
34
35#[normalizer]
36pub struct Numeric;
37
38impl Normalizer<String> for Numeric {
39    fn normalize(&self, value: &mut String) -> Result<(), String> {
40        value.retain(|c| c.is_ascii_digit());
41
42        Ok(())
43    }
44}