你这个问题有点简略,我按几种常见含义来解释“如何测 Debian 上的 Rust”,你可以看哪一个是你需要的。
rustc --version
cargo --version
如果有版本号,说明已安装:
rustc 1.75.0 (xxxxxx)
cargo 1.75.0
如果没有,用下面方式安装。
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
测试:
cargo --version
sudo apt update
sudo apt install rustc cargo
⚠️ Debian 仓库里的 Rust 通常版本较旧。
cargo new hello
cd hello
cargo run
输出:
Hello, world!
说明 Rust 编译和运行都正常。
// src/lib.rs
pub 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(性能基准)valgrind(内存)perf(CPU)cargo fuzz(模糊测试)如果你是指这一类,告诉我具体场景。
结论:
✅ Debian 对 Rust 支持非常好
✅ 可用于:
如果你能补充一句,比如:
我可以给你更精准的步骤。