3 ms·
for some reason I can not answer your subsequent reply so I do it here: I looked at your example and played a bit with it and yes I agree with you - compiler d
by FpUser 3y ago
for some reason I can not answer your subsequent reply so I do it here:
I looked at your example and played a bit with it and yes I agree with you - compiler does help in this case.
My old text:
So instead of checking if vector is not empty you check that the return result is not empty. I do not see much difference. If Rust compiler would choke when "else" clause in your example is not present I would understand your point about compiler preventing improper access.
- dtn 3y ago`x`, the value of the Vector access, only exists within the context of the first block. It does not exist in any other scope. This makes it impossible to access when the result is not valid. > If Rust compiler would choke when "else" clause in your example is not present The compiler won't choke, but it will stop you from accessing the value. It doesn't matter if you omit the `else` clause or not, the type system ensures that you can't access invalid values. Here's a bit of an example based off of @Ygg2's code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f9f779c0e4885016773bee8bf4e57363 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- steveklabnik 3y ago> for some reason I can not answer your subsequent reply so I do it here Hacker News will try and discourage really quick back and forth comments. To do so, the reply button is hidden. However, if you click on the timestamp, to go to the comment's own page, you can reply there.
- FpUser 3y agoThanks for the tip. Did not know it