在 Debian 上“测 Rust”通常指 安装 Rust 工具链并运行测试/示例程序。下面给你一套从零开始在 Debian 上验证 Rust 是否可用的常见做法。
sudo apt update
sudo apt install -y curl build-essential
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 -y rustc cargo
mkdir hello && cd hello
cargo init --name hello
编辑 src/main.rs:
fn main() {
println!("Hello from Rust on Debian!");
}
运行:
cargo run
修改 src/main.rs 或新建 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 new test_env
cd test_env
cargo build
rustup target add armv7-unknown-linux-gnueabihf
cargo build --target armv7-unknown-linux-gnueabihf
cargo bench
sudo 装 rustup.cargo/bin 在 PATH如果你说的“测 Rust”是指:
可以告诉我具体目的,我给你更针对性的方案。