From 0fd15aefe6473492fec077ed23d8e3bd94f2468f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 24 Sep 2022 23:55:59 +0100 Subject: [PATCH] document that `error(transparent)` works with structs --- src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 3d6ad81..b5dfa26 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -196,6 +196,24 @@ //! } //! ``` //! +//! Another use-case is making semver-resilient opaque error types: +//! +//! ``` +//! # use thiserror::Error; +//! /// `LibError` is public, but opaque and easy to keep compatible. +//! #[derive(Error, Debug)] +//! #[error(transparent)] +//! pub struct LibError(#[from] ErrorRepr) +//! +//! /// `ErrorRepr` is private and easy to change. +//! #[derive(Error, Debug)] +//! enum ErrorRepr { +//! # /* +//! ... +//! # */ +//! } +//! ``` +//! //! - See also the [`anyhow`] library for a convenient single error type to use //! in application code. //!