aster_forge_utils/
lib.rs

1//! Shared low-level utility helpers for Aster services.
2//!
3//! This crate holds small, dependency-light helpers that do not belong to a single domain module:
4//! boolean-like string parsing, HTTP range/validator handling, checked numeric conversions, path
5//! rendering helpers, loopback host detection, UUID/token helpers, and RAII cleanup guards. The
6//! shared error type is intentionally simple so callers can map it into richer product errors.
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
19pub mod avatar;
20pub mod backoff;
21pub mod bool_like;
22pub mod fs;
23pub mod html;
24pub mod http_range;
25pub mod http_validators;
26pub mod id;
27pub mod net;
28pub mod numbers;
29pub mod paths;
30pub mod raii;
31pub mod text;
32pub mod url;
33
34/// Result type returned by utility helpers.
35pub type Result<T> = std::result::Result<T, UtilsError>;
36
37/// Error type used by generic utility helpers.
38#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
39pub enum UtilsError {
40    /// A value failed semantic validation.
41    #[error("{0}")]
42    InvalidValue(String),
43    /// A numeric conversion would overflow, underflow, or lose sign information.
44    #[error("{0}")]
45    NumericConversion(String),
46}
47
48impl UtilsError {
49    /// Creates an invalid-value error.
50    pub fn invalid_value(message: impl Into<String>) -> Self {
51        Self::InvalidValue(message.into())
52    }
53
54    /// Creates a numeric-conversion error.
55    pub fn numeric_conversion(message: impl Into<String>) -> Self {
56        Self::NumericConversion(message.into())
57    }
58}