Skip to content

Commit f6a3c07

Browse files
authored
operators.md: mention Not trait's un-C-like behavior (#2279)
Fixes #2072.
1 parent fa6055c commit f6a3c07

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/std-traits/operators.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ Discussion points:
4444
- You could implement `Add` for two different types, e.g.
4545
`impl Add<(i32, i32)> for Point` would add a tuple to a `Point`.
4646

47+
The `Not` trait (`!` operator) is notable because it does not "boolify" like the
48+
same operator in C-family languages; instead, for integer types it negates each
49+
bit of the number, which arithmetically is equivalent to subtracting it from -1:
50+
`!5 == -6`.
51+
4752
</details>
4853

4954
[1]: https://doc.rust-lang.org/std/ops/index.html

0 commit comments

Comments
 (0)