pub struct ErrorCode { /* private fields */ }Expand description
An error code with namespace, numeric code, and operation category.
Error codes follow the format E-XXX-YYY where:
XXXis the namespace (CORE, CFG, IO, etc.)YYYis the numeric code (001-999)
§Compile-time Guarantees
All error codes are defined as const statics, providing:
- Namespace frozen at compile time (cannot be constructed at runtime)
- Code range validated (001-999)
- Impact score validated (0-1000)
- Category compatibility enforced
- Severity authority enforced (strict_severity mode)
§Construction APIs
const_new: For const statics (panics = compile error)checked_new: For runtime construction (returns Result, never panics)
§No-Copy/No-Clone Semantics
This type is part of the error identity layer and cannot be copied, cloned, or moved after const initialization. All usage is by reference.
§Zero-Allocation Guarantee
All operations are zero-allocation. Display writes directly to formatter.
§Example
use palisade_errors::{ErrorCode, OperationCategory, ImpactScore, define_error_codes, namespaces};
// Compile-time construction (panics if invalid)
const CFG_PARSE_FAILED: ErrorCode = ErrorCode::const_new(
&namespaces::CFG,
100,
OperationCategory::Configuration,
ImpactScore::new(700)
);
// Runtime construction (returns Result)
let code = ErrorCode::checked_new(
&namespaces::IO,
code_from_config,
OperationCategory::IO,
ImpactScore::checked_new(impact_from_config).unwrap()
).unwrap();
// Use by reference only
fn log_error(code: &ErrorCode) {
println!("Error: {}", code);
}
log_error(&CFG_PARSE_FAILED);Implementations§
Source§impl ErrorCode
impl ErrorCode
Sourcepub const fn const_new(
namespace: &'static ErrorNamespace,
code: u16,
category: OperationCategory,
impact: ImpactScore,
) -> Self
pub const fn const_new( namespace: &'static ErrorNamespace, code: u16, category: OperationCategory, impact: ImpactScore, ) -> Self
Create a new error code with compile-time validation (infallible in const contexts).
§Panics
Panics if:
- Code is 0 or >= 1000 (must be 001-999)
- Category is not permitted for the namespace
- Impact is not permitted for the namespace (strict_severity mode)
In const contexts, panics occur at compile time. In runtime contexts, panics occur at runtime.
§Use Case
For const static error code definitions where all values are known at compile time and violations indicate programmer error.
Sourcepub fn checked_new(
namespace: &'static ErrorNamespace,
code: u16,
category: OperationCategory,
impact: ImpactScore,
) -> Result<Self, InternalErrorCodeViolation>
pub fn checked_new( namespace: &'static ErrorNamespace, code: u16, category: OperationCategory, impact: ImpactScore, ) -> Result<Self, InternalErrorCodeViolation>
Sourcepub const fn category(&self) -> OperationCategory
pub const fn category(&self) -> OperationCategory
Get the operation category.
Sourcepub const fn namespace(&self) -> &'static ErrorNamespace
pub const fn namespace(&self) -> &'static ErrorNamespace
Get namespace reference.
Sourcepub const fn impact(&self) -> ImpactScore
pub const fn impact(&self) -> ImpactScore
Get impact score.
Sourcepub const fn impact_level(&self) -> ErrorImpact
pub const fn impact_level(&self) -> ErrorImpact
Get the detailed impact level.