File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,27 @@ pub enum DataStoreError {
165
165
}
166
166
```
167
167
168
+ Another use case is hiding implementation details of an error representation
169
+ behind an opaque error type, so that the representation is able to evolve
170
+ without breaking the crate's public API.
171
+
172
+ ``` rust
173
+ // PublicError is public, but opaque and easy to keep compatible.
174
+ #[derive(Error , Debug )]
175
+ #[error(transparent)]
176
+ pub struct PublicError (#[from] ErrorRepr );
177
+
178
+ impl PublicError {
179
+ // Accessors for anything we do want to expose publicly.
180
+ }
181
+
182
+ // Private and free to change across minor version of the crate.
183
+ #[derive(Error , Debug )]
184
+ enum ErrorRepr {
185
+ ...
186
+ }
187
+ ```
188
+
168
189
- See also the [ ` anyhow ` ] library for a convenient single error type to use in
169
190
application code.
170
191
Original file line number Diff line number Diff line change 202
202
//!
203
203
//! ```
204
204
//! # use thiserror::Error;
205
+ //! #
205
206
//! // PublicError is public, but opaque and easy to keep compatible.
206
207
//! #[derive(Error, Debug)]
207
208
//! #[error(transparent)]
You can’t perform that action at this time.
0 commit comments