refactor: validation

This commit is contained in:
Kristofers Solo 2025-09-23 08:22:37 +03:00
parent dd3b2b618b
commit fe0b153caa
Signed by: kristoferssolo
GPG Key ID: 74FF8144483D82C8
2 changed files with 4 additions and 12 deletions

View File

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