Quick draft "Result::expect" rfc#1119
Conversation
|
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: |
There was a problem hiding this comment.
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.
(And I think Option should be the same)
There was a problem hiding this comment.
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