我有一个 Rust 项目,可以在 Linux、macOS 和 Windows 10 上编译良好。
我今天使用Visual Studio 安装程序在 Windows 7 计算机上安装了以下各个组件:
VC++ 2015.3 v14.00 (v140) toolset for desktop
Windows Universal CRT SDK
(依赖)Windows 8.1 SDK
(依赖)之后,我使用官方网站rustup-init.exe
上的新版本安装了 Rust新版本安装了 Rust 。
当我cargo build
在 Windows 7 计算机上运行 Rust 项目时,它失败并显示以下消息:
error: linking with `C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\link.exe\` failed: exit code: 325595.
Run Code Online (Sandbox Code Playgroud)
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\link.exe
在我的 Windows 10 计算机上不带任何参数单独运行all 会产生一些“帮助”信息,但在我的 Windows 7 计算机上,我会收到一个包含错误消息的窗口:
The application was unable to …
Run Code Online (Sandbox Code Playgroud) 我正在使用Vec<u8>
缓冲区将二进制文件读入Rust程序.流中的两个字节代表一个big-endian u16
.
到目前为止,我已经想出如何转换为原语的唯一方法是先将u16
两个元素转换为String
s,看起来很糟糕.
码:
let vector: Vec<u8> = [1, 16].to_vec();
let vector0: String = format!("{:02x}", vector[0]);
let vector1: String = format!("{:02x}", vector[1]);
let mut vector_combined = String::new();
vector_combined = vector_combined + &vector0.clone();
vector_combined = vector_combined + &vector1.clone();
let number: u16 = u16::from_str_radix(&vector_combined.to_string(), 16).unwrap();
println!("vector[0]: 0x{:02x}", vector[0]);
println!("vector[1]: 0x{:02x}", vector[1]);
println!("number: 0x{:04x}", number);
Run Code Online (Sandbox Code Playgroud)
输出:
vector[0]: 0x01
vector[1]: 0x10
number: 0x0110
Run Code Online (Sandbox Code Playgroud) 我想要不同类型结构的集合。
AVec
不起作用,我认为因为不同的结构是不同的类型,并且Vec
只能包含一种类型。
struct Santa {
color: String,
phrase: String,
}
struct Rudolph {
speed: u32,
lumens: u32,
}
fn newSanta() -> Santa {
Santa {
color: String::from("Red"),
phrase: String::from("Ho ho ho!"),
}
}
fn newRudolph() -> Rudolph {
Rudolph {
speed: 100,
lumens: 500,
}
}
fn main() {
let santa = newSanta();
let rudolph = newRudolph();
let northerners = vec![santa, rudolph]; //fails
}
Run Code Online (Sandbox Code Playgroud)
PS C:\Users\anon> rustc xmas.rs
error[E0308]: mismatched types
--> xmas.rs:27:32
|
27 | …
Run Code Online (Sandbox Code Playgroud)