refactor: validation

This commit is contained in:
2025-09-23 08:22:37 +03:00
parent dd3b2b618b
commit fe0b153caa
2 changed files with 4 additions and 12 deletions

View File

@@ -1,5 +1,3 @@
pub mod utils;
use crate::error::Result; use crate::error::Result;
use regex::Regex; use regex::Regex;
use std::sync::OnceLock; use std::sync::OnceLock;
@@ -17,6 +15,10 @@ pub trait Validate {
} }
/// Helper function to create a lazy static Regex (reused across impls). /// Helper function to create a lazy static Regex (reused across impls).
///
/// # Panics
///
/// If no pattern found
pub fn lazy_regex(pattern: &str) -> &'static Regex { pub fn lazy_regex(pattern: &str) -> &'static Regex {
static RE: OnceLock<Regex> = OnceLock::new(); static RE: OnceLock<Regex> = OnceLock::new();
RE.get_or_init(|| Regex::new(pattern).expect("failed to compile validation regex")) RE.get_or_init(|| Regex::new(pattern).expect("failed to compile validation regex"))

View File

@@ -1,10 +0,0 @@
use crate::error::{Error, Result};
/// Trims whitespace and rejects empty strings.
pub fn validate_non_empty(input: &str) -> Result<&str> {
let trimmed = input.trim();
if trimmed.is_empty() {
return Err(Error::validation_falied("input cannot be empty"));
}
Ok(trimmed)
}