icydb 0.180.37

IcyDB — A schema-first typed query engine and persistence runtime for Internet Computer canisters
Documentation
pub mod case;
pub mod color;

use crate::{design::prelude::*, traits::Validator};

///
/// AlphaUscore
/// this doesn't force ASCII; it uses Unicode `is_alphabetic`
/// ASCII is handled by a separate validator
///

#[validator]
pub struct AlphaUscore;

impl Validator<str> for AlphaUscore {
    fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
        if !s.chars().all(|c| c.is_alphabetic() || c == '_') {
            ctx.issue(Issue::TextPattern {
                pattern: IssueTextPattern::AlphabeticUnderscore,
            });
        }
    }
}

///
/// AlphanumUscore
///

#[validator]
pub struct AlphanumUscore;

impl Validator<str> for AlphanumUscore {
    fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
        if !s.chars().all(|c| c.is_alphanumeric() || c == '_') {
            ctx.issue(Issue::TextPattern {
                pattern: IssueTextPattern::AlphanumericUnderscore,
            });
        }
    }
}

///
/// Ascii
///

#[validator]
pub struct Ascii;

impl Validator<str> for Ascii {
    fn validate(&self, s: &str, ctx: &mut dyn VisitorContext) {
        if !s.is_ascii() {
            ctx.issue(Issue::TextPattern {
                pattern: IssueTextPattern::Ascii,
            });
        }
    }
}