assert_eq!(usize::max_value(), 18446744073709551615);
但是当我运行一个简单的测试时:
use std::usize;
fn main() {
println!("{}", usize::max_value());
}
它打印:4294967295
我的项目刚刚初始化并且有两行 use std::usize;
和 println!("{}", usize::max_value());
已添加,其他未更改。
我的 rustc --version --verbose
输出:
rustc 1.41.1 (f3e1a954d 2020-02-24)
binary: rustc
commit-hash: f3e1a954d2ead4e2fc197c7da7d71e6c61bad196
commit-date: 2020-02-24
host: i686-pc-windows-msvc
release: 1.41.1
LLVM version: 9.0
删除 Rust 并使用 64 位 Windows rustup 安装程序重新安装后,我得到:
Current installation options:
default host triple: x86_64-pc-windows-msvc
default toolchain: stable
profile: default
modify PATH variable: yes
但是当我运行 rustup toolchain list
时,它会打印出一个项目:
stable-i686-pc-windows-msvc (default)
这里发生了什么?
最佳答案
正如 usize
的文档所说:
The size of this primitive is how many bytes it takes to reference any location in memory. For example, on a 32 bit target, this is 4 bytes and on a 64 bit target, this is 8 bytes.
4294967295
是 32 位整数的最大大小;因此表明您正在为 32 位平台编译。
您的 rustc
输出证实了这一点:
host: i686-pc-windows-msvc
您已经安装了 32 位 Windows 编译器。 64 位编译器说 x86_64-pc-windows-*
。
您可以将默认的 rustup 主机更改为 64 位:
rustup set default-host x86_64-pc-windows-msvc
然后您可能需要卸载并重新安装稳定的工具链以将其切换到 64 位。
另见:
关于windows - 为什么 usize::max_value() 在 64 位 Windows 上返回无符号 32 位整数的最大值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60527989/