-
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
Quick draft "Result::expect" rfc #1119
Conversation
|
||
# Drawbacks | ||
|
||
- It involves adding a new method to a core rust type. |
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.
Not a drawback per se.
Seems logical to me. After you get to know .expect() on Option, you'll expect to find the method on Result too. |
This would be great for quick and dirty scripts. It would also make one of the first examples in the rust book a little easier to read:
|
|
||
# Detailed design | ||
|
||
Add a new method to the same `impl` block as `Result::unwrap` that takes a `&str` message and |
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.
I dislike this signature, and much prefer:
impl<T, U: Debug, V: Display> Foo<T, V> for Result<T, U> {
fn expect(self, msg: V) -> T {
match self {
Ok(v) => v,
Err(e) => panic!("Error: {} ({:?})", msg, e)
}
}
}
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.
(And I think Option should be the same)
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.
Ooh, interesting idea. This would allow passing format_args!
for formatted messages
I think |
@grissiom Possibly, this RFC just brings the avaliable methods into line with Option's methods. |
@grissiom, I completely agree. I think this should at least be discussed before accepting this RFC so we'd only have to deprecate one method, not two, if this were accepted. |
Yes, but it can be deprecated. |
@gsingh93 @thepowersgang OK, when I have time, I will open an other RFC to discuss |
This RFC is now entering the week-long final comment period. |
I still REALLY think that this should take |
I don't think the point about Which of these are more helpful? Maybe this issue should be raised elsewhere though because it's not a problem with |
I suspect this is the right way to think about it. For better or worse, |
The text as written now is a bit unclear. I'd really like it to explicitly provide the signature and implementation (since it should be trivial to provide, and is the entire point of the RFC). |
@gkoz That should be raised somewhere, probably on the offending error type, making |
Agreed. We could change the conventions for error types to have more informative |
Edit: see below. @BurntSushi: I think the cases are different. The Also, we can demand a rarer trait like |
@bluss but that part of discussion was about the value inside the |
@gkoz Oops! I'm sorry for the noise. |
The consensus among the libs team is to accept this RFC now. The matter of generalizing the argument of Thanks for the RFC @thepowersgang! |
See also rust-lang/rust#25359 for implementation
Rendered