error_node

Macro error_node 

Source
error_node!() { /* proc-macro */ }
Expand description

Function-like proc macro to construct error nodes. The body requires the following format: type (name)<variants> [= (string)] where name is the name to give to the error node (an enum), variants is a comma-separated list of other errors (both leaves and nodes), and string is an optional string to use rather than the node name when printing the error node.

§Examples:

use hierrorchy::{error_leaf, error_node};
use std::error::Error;

#[error_leaf(format!("error child 1"))]
pub struct ErrorChild1 {}

error_node! { type MyErrorNode<ErrorChild1> = "custom prefix" }

§Variants with paths

Since version 0.2.0

error_node also accept variants in the form of paths, e.g. std::io::Error.

This allows to write:

error_node! { type MyErrorNode<std::io::Error> = "custom message" }

rather than:

use std::io::Error as IoError;
error_node! { type MyErrorNode<IoError> = "custom message" }