-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
all Error types should be public? #39381
Comments
Maybe a dupe of #22639, though this might be more about a general principle for Error types. |
@rust-lang/libs, this seems relevant to the libz blitz and associated API guideline generation. |
Thanks! I filed rust-lang/api-guidelines#69 to follow up with a guideline. |
We discussed this in the libs team meeting today. The problem with allowing public constructors is that it precludes you ever extending the error with additional fields or variants. An alternative is to make sure there are enough public accessors that you can write tests using the accessors, rather than by ginning up an error. |
|
@getreu So for |
In order to test the error behaviour of a function you need an error struct to compare with. For example:
since
ParseIntError
is private, I have to generate one by doing something wrong, likeu8::from_str("257")
. This leads to the following test:If error types where public I would rather instantiate one and write:
Maybe there is a reason I do not see why they are private and there is better more idiomatic way of doing error comparison?
The text was updated successfully, but these errors were encountered: