Opaque error type with a user-defined kind.
opaquerr is a small no_std error helper for libraries that want to expose a
stable error kind while keeping the concrete error payload opaque. The kind stays
easy to compare and match on, while the displayed message can come from the kind,
a custom message, or an underlying source error.
[dependencies]
opaquerr = "<version>"Enable alloc when you need boxed source errors:
[dependencies]
opaquerr = { version = "<version>", features = ["alloc"] }opaquerr::define_kind! {/// Category for a library error.pubErrorKind{/// Input is invalid.Invalid => "input is invalid",/// Anything not covered by the categories above.Other => "other error",}}
opaquerr::define_error! {/// Library error.pubError(ErrorKind)}pubfnparse(input:&str) -> Result<(),Error>{if input.is_empty(){returnErr(Error::with_static_message(ErrorKind::Invalid,"empty input"));}Ok(())}With the alloc feature enabled, define_error! can map source errors once and then
propagate them with ?:
opaquerr::define_error! {pubError(ErrorKind)
from {
core::num::ParseIntError => ErrorKind::Other,}}All notable changes to this library are documented in the CHANGELOG.md.
This project is distributed under the MIT software license. See the LICENSE file for details.