-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Box error alias #2820
base: master
Are you sure you want to change the base?
Box error alias #2820
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other, similar changes throughout are not marked to reduce clutter, but they should all be addressed.
Can we also get? type Result<T> = std::result::Result<T, BoxError> |
My recent preference (and that of SNAFU) has been type Result<T, E = BoxError> = std::result::Result<T, E>; This way, you don't have to go all the way back to |
So this would look like type BoxError = Box<dyn Error + Send + Sync>;
type Result<T, E = BoxError> = std::result::Result<T, E>; in the module edit typo |
Yep. Note that I'm not voting one way or other on the actual inclusion of this alias, just pointing out what I've found to be more ergonomic for other type aliases. |
+@yoshuawuyts who was considering writing an RFC for a better type erased error type in the near future. I think the rationale in this RFC against a dedicated erased error type of "it is not clear what the best design would be" and "it is not clear if one is necessary" are definitely not sufficient to rule out that idea. With that in mind, I would be opposed to accepting this RFC before making more progress on a type erased error type design, because I believe we would not want the standard library to expose both that and this type alias. We should expose one and it should be the one that we feel comfortable recommending for general use. |
Especially if we provide a How far can we get if this RFC instead provided a newtype? What might we want to change in the future that would be prevented? |
Until we have specialization, my "vote" would be for a newtype that Personally, I feel providing shortcuts or simplifications in the stdlib for a type-erased error type that doesn't |
Not being able to implement I see the argument about it being confusing if you have both a
Am I missing any? Edit: typos |
There is the open question of whether to implicitly carry a Backtrace in an |
Support for |
I'd love to see something like this. My preference would be to make the type a "primitive" and name it I agree that at the same time, Furthermore I vote for taking I'd like to take a second and note that I'm not capable of expressing just how significant and game changing this RFC would be. Daily, new Rust users run into issues with error types and not really understanding the intricacies with error enumerations and |
I second making this type alias |
Future PossibilityIn the future it may be possible to move the Error trait into |
We cannot make If we had
I suppose |
I've been using @dtolnay what do you think a MVP for an opaque type-erased error type in |
I think it's early to push to stabilize anyhow::Error or a subset of its functionality in std. Every previous iteration that anyhow builds on has taken some time to understand the nuances and improve. I think if we still think anyhow is the best approach ~12 months after it was released, we could consider how to move forward. For now I think the most important work toward a standard type-erased error type would be helping to get specialization mature enough that we could do a From<E> and Error impl on the same type. |
Rendered
Following on from a conversation on internals.rust-lang.org, I have written an RFC for adding
BoxError
tostd::error
. Although it is a small change, it may have a larger impact on the user experience if it becomes ubiquitous, and so I thought it was worth writing up the motivations and drawbacks in an RFC.It's the first time I've done anything like this, so be kind to me! 😳