知识卡片
区分按位运算与逻辑判断
对 u8 使用 ! 会翻转全部八位,如 !0xe0u8 得 0x1f。有符号整数右移补符号位,无符号整数右移补零。测整数是否为零要写 n == 0。x & BIT != 0 会先按位取掩码,再比较结果。&& 和 || 只接收 bool,必要时才计算右侧,例如 index < len && check(index) 只在下标检查为真时调用 check。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Expressions 判断边界算术、位运算和布尔短路 · 查看原书依据
Rust also has the two short-circuiting logical operators && and ||. Both operands must have the exact type bool.
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第05章《Expressions》|判断边界算术、位运算和布尔短路,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch05.xhtml#arithmetic-bitwise-comparison-and-logical-operators`
- 结论依据:原文对照按位取反、掩码组合和两个布尔短路运算符,指明其类型要求和优先级。
- 原始内容:Rust also has the two short-circuiting logical operators && and ||. Both operands must have the exact type bool.