Skip to main content

ass_core/utils/errors/
constructors.rs

1//! Convenience constructors for [`CoreError`] variants.
2//!
3//! Provides ergonomic factory methods on [`CoreError`] that delegate to the
4//! specialized error-creation helpers in the sibling submodules.
5
6use super::{encoding, format, resource, CoreError};
7
8impl CoreError {
9    /// Create color error from invalid format
10    pub fn invalid_color<T: ::core::fmt::Display>(format: T) -> Self {
11        format::invalid_color(format)
12    }
13
14    /// Create numeric error from parsing failure
15    pub fn invalid_numeric<T: ::core::fmt::Display>(value: T, reason: &str) -> Self {
16        format::invalid_numeric(value, reason)
17    }
18
19    /// Create time error from invalid format
20    pub fn invalid_time<T: ::core::fmt::Display>(time: T, reason: &str) -> Self {
21        format::invalid_time(time, reason)
22    }
23
24    /// Create UTF-8 error with position
25    #[must_use]
26    pub const fn utf8_error(position: usize, message: alloc::string::String) -> Self {
27        encoding::utf8_error(position, message)
28    }
29
30    /// Create feature not supported error
31    #[must_use]
32    pub fn feature_not_supported(feature: &str, required_feature: &str) -> Self {
33        resource::feature_not_supported(feature, required_feature)
34    }
35
36    /// Create resource limit error
37    #[must_use]
38    pub fn resource_limit_exceeded(resource: &str, current: usize, limit: usize) -> Self {
39        resource::resource_limit_exceeded(resource, current, limit)
40    }
41}