运算符、表达式和类型转换
C 程序员看 Rust 运算符,最容易误判的不是 +、-、*、/ 长得像不像,而是 C 里很多自动发生的转换,在 Rust 里不会自动发生。
C 代码里常见这种写法:
#include <stdint.h>
#include <stddef.h>
uint8_t version = 1;
size_t len = 128;
uint32_t total = version + len;
if (total) {
/* ... */
}
Rust 会要求你把类型关系写清楚:
阅读更多