[][src]Crate errormake

A macro for automatically generating structs which implement the Error trait from std::error.

The errormake! macro generates a struct which implements an error and may optionally contain a description and/or a source error. The resulting struct may be either public or private to the module.

Here is an example of using some of its functionality:

use errormake::errormake;

errormake!(pub ExampleError);

// Create an error with no description or source
let error1 = ExampleError::new();
// Create an error with a description, but no source
let error2 = ExampleError::with_description(String::from("Error description"));
// Create an error with a source, but no description
let error3 = ExampleError::with_source(Box::new(error1));
// Create an error with a source and a description
let error4 = ExampleError::with_source_and_description(Box::new(error3), String::from("Error description"));

If making a public error struct, you can also add custom documentation through the doc attribute, as follows:

use errormake::errormake;

// The `DocumentedError` struct now has a documentation, which will
// show up if `cargo doc` is run.
errormake!(#[doc="Documentation comments"] pub DocumentedError);

You can also convert the type of contained error into a dynamic Error object as follows:

use std::error::Error;
use errormake::errormake;

let error: ExampleError<dyn Error + 'static> = ExampleError::new().into_dynamic();



The macro used to generate basic Error structs.



An example of an error struct made by errormake