Skip to main content

DomainReason

Trait DomainReason 

Source
pub trait DomainReason:
    PartialEq
    + Display
    + Debug
    + Send
    + Sync
    + 'static { }
Expand description

Marker trait for domain-specific error reason types.

Implement this on your project’s error reason enum so it can be used as the generic parameter of StructError.

§Constraints

BoundReason
Display + DebugErrors must be printable for diagnostics and logging.
PartialEqEnables assertion in tests (assert_eq!(err.reason(), MyReason::Foo)).
Send + SyncRequired for StructError to be Send + Sync, which is needed when errors cross async task boundaries or are captured by anyhow::Error / Box<dyn Error>.
'staticEnables type erasure via dyn Error and storage in SourceFrame.

These bounds match the de-facto standard for Rust error types (the Error trait requires 'static, and practical use requires Send for thread safety).

§Derive

Prefer #[derive(OrionError)] (requires the derive feature), which also implements ErrorCode and ErrorIdentityProvider.

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.

Implementors§