From 765cd2a44c1f2acf80cc152e5b978c3d8db153be 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..eb6ced2 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. //!