Crate throwing

source ·
Expand description

This crate implements a #[throws(...)] macro that allows you to easily declare what errors a function can return. This will allow you to exhaustively match on all possible errors. It is inspired by declared exceptions in Java.

The #[throws(...)] macro will automatically generate an enum that can represent all declared errors, generate From<T> implementations for each variant, and change the return type of the function to an appropriate Result<T, E>. The error type will also have implementations of Error, Display and Debug.

Additionally, it can generate From<T> implementation for upcasting errors, that is converting an error of a type with fewer variants to one with more variants.

Macros

  • Creates a new composite error type with a given name.

Traits

  • Represents an error that can be upcasted to a different error type.

Attribute Macros

  • Creates a new composite error type for a function to return.