Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Geoxion9013yHave a ++ because Rust is my favorite language ❤️
This is used for signalling of intent. When pattern matching, you may know that certain patterns will never happen. So then you plop in an unreachable.
The compiler should optimize it so that it still does get checked, but only as the unhappy path. Then a panic happens.
If you absolutely know for certain that it will never happen, then you can also use: https://doc.rust-lang.org/std/hint/...
Now it will be Undefined Behavior to run that branch, but it can potentially be optimized harder. -
Geoxion9013y@Ranchonyx it's not a function! 🙂
The exclamation mark is used for macros to differentiate them. You never have to guess like you have to do in C and C++ -
@Ranchonyx Yeah, it's a macro that crashes the thread with a panic. It lets you mark a branch that should never be reachable unless you have a bug or invalid state somewhere. There's also "todo!()" which basically does the same but with a slightly different error message. It lets you check the rest of the code without the compiler whining about missing return values and shit.
The compiler figured out this part was guaranteed to be always unreachable and marked the macro unreachable.
Unreachable
rant