pub trait CqrsErrorCode:
Debug
+ Display
+ Clone
+ MaybeSend
+ MaybeSync
+ 'static {
// Required methods
fn domain() -> &'static str;
fn domain_prefix() -> u16;
fn error_index(&self) -> u16;
fn http_status(&self) -> StatusCode;
// Provided methods
fn internal_code(&self) -> u16 { ... }
fn code_string(&self) -> String { ... }
fn error(&self, message: impl Into<String>) -> CqrsError
where Self: Sized { ... }
}Expand description
Trait that all domain error codes must implement.
Each domain defines its own enum implementing this trait. The trait provides the contract for error code metadata.
§Example
ⓘ
use cqrs_rust_lib::define_domain_errors;
define_domain_errors! {
domain: "plan",
prefix: 4,
errors: {
NotFound => (1, StatusCode::NOT_FOUND, "NOT_FOUND"),
SlugExists => (2, StatusCode::CONFLICT, "SLUG_EXISTS"),
}
}Required Methods§
Sourcefn domain_prefix() -> u16
fn domain_prefix() -> u16
Domain prefix for internal codes (0-9) Each domain gets a unique prefix.
Sourcefn error_index(&self) -> u16
fn error_index(&self) -> u16
Unique error index within the domain (0-999)
Sourcefn http_status(&self) -> StatusCode
fn http_status(&self) -> StatusCode
HTTP status code for this error
Provided Methods§
Sourcefn internal_code(&self) -> u16
fn internal_code(&self) -> u16
Full internal code: domain_prefix * 1000 + error_index Example: Tenant (4) + NotFound (1) = 4001
Sourcefn code_string(&self) -> String
fn code_string(&self) -> String
String representation of the error code for JSON serialization Format: DOMAIN_ERROR_NAME (e.g., “PLAN_NOT_FOUND”)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.