r/rust • rust • May 26 '16

Announcing Rust 1.9

http://blog.rust-lang.org/2016/05/26/Rust-1.9.html
301 Upvotes

125 comments sorted by

View all comments

Show parent comments

14

u/steveklabnik1 rust May 26 '16

But Rust 1.9 makes those errors recoverable? How is it different from Result at all then?

It makes them recoverable only because there are very specific situations in which they should be recovered, like what's covered in the post.

Using Result type in this scenario would mean that I'd need to check for absolutely everything that may go wrong, and this amount of checks would turn my code into a complete mess that resembles Go or some unit test code.

Well, with try!, (and the upcoming ?), I guess I just disagree that this is particularly onerous. You propogate Results up to the level that you want to handle the error, and then handle it.

4

u/Hauleth octavo · redox May 26 '16

I still hope that ? will die in pain. Instead I would ♥ |> operator.

10

u/i_r_witty May 27 '16

but then my bees function will be less awesome.

fn bees() -> Result<Honey, Pain>{...}

bees()?

3

u/SimonSapin servo May 27 '16

I assume you don’t mean just changing the syntax. What would |> do, and why would it be preferable to ? ?

1

u/Hauleth octavo · redox May 30 '16

It would be pipe, it would work like | in shells not like try! in Rust.

So these 2 pieces of code would be equivalent:

result |> Foo::bar

result.and_then(Foo::bar)

In theory we could reuse | operator, but IMHO it would be abuse.

6

u/desiringmachines May 27 '16

I wish you would not use language like "die in pain" when talking about language features you don't like. :-\ You can be emphatic without being vitriolic.

1

u/LordJZ May 26 '16 edited May 26 '16

As far as I remember, try! panics when the argument is an error. So it won't help the scenario at all. I am not aware of the "upcoming ?", would be nice of you to provide a link.

Edit: I was wrong.

11

u/staticassert May 26 '16 edited May 26 '16

try! returns Err(e) on error.

11

u/steveklabnik1 rust May 26 '16

Try does not panic, it returns a Result, specifically, the Err case.

https://github.com/rust-lang/rfcs/blob/4b4fd5146c04c9c284094aad8f54ca5c2093c7f2/text/0243-trait-based-exception-handling.md is the question mark, basically, try!(foo) becomes foo?

3

u/LordJZ May 26 '16

Okay, thanks for the link and for the discussion. The ? operator certainly does look much better. That might actually be a solution. Still rather ugly in my opinion, but foo? is so much better than try!(foo).

1

u/steveklabnik1 rust May 26 '16

No problem. :)