Skip to main content

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#![deny(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
8#![cfg_attr(
9    not(test),
10    deny(
11        clippy::unwrap_used,
12        clippy::unreachable,
13        clippy::expect_used,
14        clippy::panic,
15        clippy::unimplemented,
16        clippy::todo
17    )
18)]
19
20pub mod avatar;
21pub mod backoff;
22pub mod bool_like;
23pub mod fs;
24pub mod html;
25pub mod http_range;
26pub mod http_validators;
27pub mod id;
28pub mod net;
29pub mod numbers;
30pub mod paths;
31pub mod raii;
32pub mod text;
33pub mod url;
34
35/// Result type returned by utility helpers.
36pub type Result<T> = std::result::Result<T, UtilsError>;
37
38/// Error type used by generic utility helpers.
39#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
40pub enum UtilsError {
41    /// A value failed semantic validation.
42    #[error("{0}")]
43    InvalidValue(String),
44    /// A numeric conversion would overflow, underflow, or lose sign information.
45    #[error("{0}")]
46    NumericConversion(String),
47}
48
49impl UtilsError {
50    /// Creates an invalid-value error.
51    pub fn invalid_value(message: impl Into<String>) -> Self {
52        Self::InvalidValue(message.into())
53    }
54
55    /// Creates a numeric-conversion error.
56    pub fn numeric_conversion(message: impl Into<String>) -> Self {
57        Self::NumericConversion(message.into())
58    }
59}