Hacker News new | ask | show | jobs
by richardwhiuk 2015 days ago
The former code is more equivalent to:

  let file = match file {
    Some(file) => file,
    None => panic!("file was null");
  };
1 comments

Which you'd never write in practice since `expect` exists
Can you say more here, I don't have the context.
This code is identical to

  let file = file.expect("file was null");
That is, the "expect" method does exactly this.
I like Rust from what I've tried. But I'd have preferred something like this:

  let file = file.unwrapOrPanicWith("file was null");
option.expect(message) doesn't semantically make sense.
There was some discussion about this when the method was named; you're not alone. In the end, it is what it is. You could define your own method like that if you really wanted to.
I read it as expect (prepare) for the worst!