Skip to content

Fix documentation example for transparent error pattern#444

Closed
veeceey wants to merge 1 commit intodtolnay:masterfrom
veeceey:fix/issue-439-doc-example
Closed

Fix documentation example for transparent error pattern#444
veeceey wants to merge 1 commit intodtolnay:masterfrom
veeceey:fix/issue-439-doc-example

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 13, 2026

The documentation example showing how to use #[error(transparent)] with #[from] on a struct wrapping an enum had a placeholder (...) that caused compilation errors when users tried to complete it.

Changes

  • Replaced the placeholder with a concrete example showing an error variant with #[from]
  • Added hidden helper code demonstrating the From trait chain works correctly
  • Included a working example function using the ? operator

Key Detail

The important pattern shown is that intermediate functions should return Result<(), ErrorRepr> so the conversion chain works: InvalidInputErrorErrorReprPublicError

Testing

  • All doc tests pass
  • All existing tests pass

Fixes #439

The example showing how to use #[error(transparent)] with #[from] on a
struct wrapping an enum had a placeholder (...) that didn't compile when
users tried to complete it.

Added a concrete example showing:
- A variant in ErrorRepr with #[from] attribute
- Helper code demonstrating the From trait chain works correctly
- A working example function that uses the ? operator

The key insight is that functions need to return Result<(), ErrorRepr>
for the From chain to work: InvalidInputError -> ErrorRepr -> PublicError

Fixes dtolnay#439
@dtolnay dtolnay closed this Feb 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

example from documentation does not compile

2 participants