mirror of
https://github.com/kristoferssolo/tg-relay-rs.git
synced 2025-12-20 11:04:41 +00:00
refactor: validation
This commit is contained in:
parent
dd3b2b618b
commit
fe0b153caa
@ -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"))
|
||||
@ -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)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user