Skip to content

Commit 8e8e41d

Browse files
authored
Merge pull request #195 from matklad/error-transparent
document that `error(transparent)` works with structs
2 parents c79b023 + 765cd2a commit 8e8e41d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,24 @@
196196
//! }
197197
//! ```
198198
//!
199+
//! Another use-case is making semver-resilient opaque error types:
200+
//!
201+
//! ```
202+
//! # use thiserror::Error;
203+
//! /// `LibError` is public, but opaque and easy to keep compatible.
204+
//! #[derive(Error, Debug)]
205+
//! #[error(transparent)]
206+
//! pub struct LibError(#[from] ErrorRepr);
207+
//!
208+
//! /// `ErrorRepr` is private and easy to change.
209+
//! #[derive(Error, Debug)]
210+
//! enum ErrorRepr {
211+
//! # /*
212+
//! ...
213+
//! # */
214+
//! }
215+
//! ```
216+
//!
199217
//! - See also the [`anyhow`] library for a convenient single error type to use
200218
//! in application code.
201219
//!

0 commit comments

Comments
 (0)