error-kind
Separate Error from ErrorKind with convenient derive macros!
Alpha Software: The API is unstable and may contain breaking changes in any release. Do not depend on
error-kindfor a stable public interface yet.
Basic Usage
The most basic usage of error-kind is with a simple error/kind combo.
use ;
// This will print:
// error: some failure
println!;
The power of this separation is that you can configure your crate to collect additional information without changing the surrounding code. This may, however, affect the size and runtime cost of the containing error.
For example, you can opt-into collection of dynamic error descriptions like this.
use ;
// Notice we only changed `MyError`?
// This will now print:
// error: some failure: dynamic details: 1
println!;
If you want your users to be able to inspect the error kind, you can grant access to it by providing a function.
use ;
See the full documentation to learn about all the
different error envelopes, as well as some complex use-cases like composing and
organizing related error kinds into ErrorDomains!
When to Use
You should use error-kind when you can accept a separation between the Error
and ErrorKind types. As demonstrated, this separation is valuable because it
grants you flexibility in how you can change your error types as your crate
evolves (or based on user configuration).
If you are creating a binary, it's recommended to use an error-erasing crate
like anyhow.
If you want error and error kind to be the same type, you could use
thiserror.
Changelog
See CHANGELOG for release history.
Contributing
We welcome contributions!
Please read the CONTRIBUTING guide before contributing.
License
Licensed under either the Apache License, Version 2.0 or MIT license, at your option.