diff --git a/src/Snafu.md b/src/Snafu.md index 442c5bbd..5f0adf61 100644 --- a/src/Snafu.md +++ b/src/Snafu.md @@ -9,6 +9,7 @@ unique situations. - [`display`](#controlling-display) - [`source`](#controlling-error-sources) - [`visibility`](#controlling-visibility) +- [`whatever`](#controlling-stringly-typed-errors) ## Controlling `Display` @@ -242,6 +243,32 @@ enum Error { } ``` +## Controlling stringly-typed errors + +This allows your custom error type to behave like the [`Whatever`][] +error type. Since it is your type, you can implement additional +methods or traits. When placed on a struct or enum variant, you will +be able to use the type with the [`whatever!`][] macro as well as +`whatever_context` methods, such as [`ResultExt::whatever_context`][]. + +```rust +# use snafu::Snafu; +#[derive(Debug, Snafu)] +enum Error { + SpecificError { username: String }, + + #[snafu(whatever, display("{}", message))] + GenericError { + message: String, + + // Having a `source` is optional, but if it is present, it must + // have this specific attribute and type: + #[snafu(source(from(Box, Some)))] + source: Option>, + } +} +``` + ## Controlling how the `snafu` crate is resolved If the `snafu` crate is not called `snafu` for some reason, you can