Skip to main content

united_error

Attribute Macro united_error 

Source
#[united_error]
Expand description

Defines a compile-time alias for a set of errors (a united error).

The generated struct is a zero-sized type (ZST) that carries no runtime data. It serves purely as a named grouping of error types, allowing #[throws] and match_error! to refer to the whole set at once.

§Syntax

use struct_error::united_error;

#[united_error(NotFound, Timeout)]
pub struct AppError;

§Examples

use struct_error::{error, united_error, throws, match_error, throw};

#[error]
pub struct NotFound;

#[error]
pub struct Timeout;

#[united_error(NotFound, Timeout)]
pub struct AppError;

#[throws(AppError)]
fn risky() {
    throw!(NotFound);
}