你说的“在 Debian 测 Rust”通常可能有几种含义,我分别说明,你可以对号入座:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
安装完成后:
source "$HOME/.cargo/env"
测试:
rustc --version
cargo --version
sudo apt update
sudo apt install rustc cargo
测试:
rustc --version
cargo new hello --bin
cd hello
cargo run
输出:
Hello, world!
Rust 自带测试框架:
// src/main.rs
fn add(a: i32, b: i32) -> i32 {
a + b
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_add() {
assert_eq!(add(2, 3), 5);
}
}
运行测试:
cargo test
可以:
cargo bench 做性能测试cargo clippy 做代码质量检查cargo audit 检查依赖安全安装工具:
rustup component add clippy
cargo install cargo-audit
如果你说的“测 Rust”是指:
可以告诉我具体场景,我可以给你更精确的命令。