3 ms·
The former code is more equivalent to: let file = match file { Some(file) => file, None => panic!("file was null"); };
by richardwhiuk 6y ago
The former code is more equivalent to:
let file = match file {
Some(file) => file,
None => panic!("file was null");
};
- timidger 6y agoWhich you'd never write in practice since `expect` exists
- vikiomega9 6y agoCan you say more here, I don't have the context.
- steveklabnik 6y agoThis code is identical to let file = file.expect("file was null"); That is, the "expect" method does exactly this.
- jeswin 6y agoI 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.
- jack1243star 6y agoI read it as expect (prepare) for the worst!
- steveklabnik 6y agoThere 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.