google/comprehensive-rust

Call out `Not` trait in speaker notes

fw-immunant opened this issue · 0 comments

We have a slide on the various operator traits in the standard library, which focuses on their overall design and how to implement these for our own types so we can use operator syntax with them. This is good, but there are a couple semantic surprises in how Rust operators behave, which we should note explicitly.

One is that the Not operator (!) does not "boolify" like the C/C++/JS incarnations of this operator; it instead negates each bit of an integer, so !5u8 is 250.

Another is that the &&/|| operators are not tied to traits because they are lazy in their right-hand sides, so they cannot be used with user-defined types.