Code paths

Some paths should never be traversed and, in our code, that is usually a condition for our code to work properly. If we are receiving bad input data, we might want to return an error, but if our library is being misused, we might prefer to panic. Sometimes, we also want to make sure that it's impossible for a variable to be out of some bounds once it gets to the logic of our function, to avoid security flaws, for example. In those cases, the unreachable!() macro, or even the explicit panic!() macro, can help us.

There is another path that might not be ready to be traversed yet. While our crate is being implemented, we can use the unimplemented!() macro, as we saw before in some examples, to indicate that the code we are writing ...

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.