Skip to main content

orion_error/core/
domain.rs

1use std::fmt::{Debug, Display};
2
3/// Marker trait for domain-specific error reason types.
4///
5/// Implement this on your project's error reason enum so it can be used
6/// as the generic parameter of [`StructError`](crate::StructError).
7///
8/// # Constraints
9///
10/// | Bound | Reason |
11/// |-------|--------|
12/// | `Display` + `Debug` | Errors must be printable for diagnostics and logging. |
13/// | `PartialEq` | Enables assertion in tests (`assert_eq!(err.reason(), MyReason::Foo)`). |
14/// | `Send + Sync` | Required for `StructError` to be `Send + Sync`, which is needed when errors cross async task boundaries or are captured by `anyhow::Error` / `Box<dyn Error>`. |
15/// | `'static` | Enables type erasure via `dyn Error` and storage in `SourceFrame`. |
16///
17/// These bounds match the de-facto standard for Rust error types (the Error trait
18/// requires `'static`, and practical use requires `Send` for thread safety).
19///
20/// # Derive
21///
22/// Prefer `#[derive(OrionError)]` (requires the `derive` feature), which
23/// also implements [`ErrorCode`](crate::reason::ErrorCode) and
24/// [`ErrorIdentityProvider`](crate::reason::ErrorIdentityProvider).
25pub trait DomainReason: PartialEq + Display + Debug + Send + Sync + 'static {}