The Not Operator

Personally, I find is_hot() == false to be a bit weird to read. If we were having a conversation, I wouldn’t say “make sure that it is hot is false.” I wouldn’t say “make sure that it is hot is not true.” A more normal way to say this is “make sure that it is not hot.” The not is the important bit. It would sure be nice if there was a way in Rust to say not…​wouldn’t it?

Well, with that kind of an introduction, and the name of this subsection, I’m sure you can see what’s coming next. I’d like to introduce you to the not operator! So far, the operators we’ve seen have been binary operators, meaning they work on two values at once. For example, with ==, we say something like x == y, comparing the values x and y. The not operator is unary, meaning it only works on one value. Let’s see it in action:

Get hands-on with 1200+ tech skills courses.