1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-01-08 00:57:56 +02:00

operators.md: mention Not trait's un-C-like behavior (#2279)

Fixes #2072.
This commit is contained in:
Frances Wingerter 2024-08-13 14:27:49 +00:00 committed by GitHub
parent fa6055c297
commit f6a3c07ea3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -44,6 +44,11 @@ Discussion points:
- You could implement `Add` for two different types, e.g.
`impl Add<(i32, i32)> for Point` would add a tuple to a `Point`.
The `Not` trait (`!` operator) is notable because it does not "boolify" like the
same operator in C-family languages; instead, for integer types it negates each
bit of the number, which arithmetically is equivalent to subtracting it from -1:
`!5 == -6`.
</details>
[1]: https://doc.rust-lang.org/std/ops/index.html