Skip to main content

rskit_validation/
rules.rs

1//! Stateless validation predicates.
2
3/// Returns `true` if `value` looks like a valid e-mail address.
4pub fn validate_email(value: &str) -> bool {
5    let Some((local, domain)) = value.split_once('@') else {
6        return false;
7    };
8    !local.is_empty() && domain.contains('.') && !domain.starts_with('.') && !domain.ends_with('.')
9}
10
11/// Returns `true` if `value` is an absolute HTTP or HTTPS URL.
12pub fn validate_url(value: &str) -> bool {
13    value.starts_with("http://") || value.starts_with("https://")
14}
15
16/// Returns `true` if `value` is a valid UUID (any version, hyphenated or not).
17pub fn validate_uuid(value: &str) -> bool {
18    value.parse::<uuid::Uuid>().is_ok()
19}