aster_forge_validation/
lib.rs

1//! Shared validation helpers for Aster services.
2//!
3//! The crate collects validation routines that were previously repeated in service code, including
4//! display text, frontend asset URLs, email handling, and filename handling. It keeps validation
5//! errors as plain messages so API layers and domain services can decide how to present or translate
6//! them.
7#![cfg_attr(
8    not(test),
9    deny(
10        clippy::unwrap_used,
11        clippy::unreachable,
12        clippy::expect_used,
13        clippy::panic,
14        clippy::unimplemented,
15        clippy::todo
16    )
17)]
18
19/// Display text and public asset URL validation helpers.
20pub mod display;
21/// Email validation and normalization helpers.
22pub mod email;
23/// Email allow/block list normalization and matching helpers.
24pub mod email_policy;
25/// File and folder name validation helpers.
26pub mod filename;
27
28/// Result type returned by validation helpers.
29pub type Result<T> = std::result::Result<T, ValidationError>;
30
31/// Error returned when validation fails.
32#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
33#[error("{message}")]
34pub struct ValidationError {
35    message: String,
36}
37
38impl ValidationError {
39    /// Creates a validation error with a user-facing message.
40    pub fn new(message: impl Into<String>) -> Self {
41        Self {
42            message: message.into(),
43        }
44    }
45
46    /// Returns the validation failure message.
47    #[must_use]
48    pub fn message(&self) -> &str {
49        &self.message
50    }
51}
52
53#[cfg(test)]
54mod tests {
55    use super::ValidationError;
56
57    #[test]
58    fn validation_error_preserves_and_displays_message() {
59        let error = ValidationError::new("invalid value");
60
61        assert_eq!(error.message(), "invalid value");
62        assert_eq!(error.to_string(), "invalid value");
63    }
64}