安装rust
安装
# windows:
https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe
根据提示,安装msvc和windows sdk
# linux:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 安装完成后需要刷新环境变量
source "$HOME/.cargo/env"
安装完成后,使用 rustc --version 验证安装成功,
# 查看版本
rustc --version
# 显示安装信息
rustup show
# 更新
rustup update
# 显示本地帮助手册
rustup doc
# 卸载
rustup self uninstall
开发工具与插件
开发工具可以选择vscode,插件可以使用rust-analyzer,注意,插件市场有一个山寨的,请看清楚作者为rust-lang.org
编写hello,world
# vi main.rs
fn main() {
println!("Hello, world!");
}
# 使用rustc编译源文件
rustc main.rs
使用cargo构建和包管理器
# 显示管理版本
cargo --version
# 创建一个新项目
cargo new hello_cargo
# 编译,编译debug版本
cargo build
# 编译,编译release版本
cargo build --release
# 编译并运行
cargo run
# 编译检查
cargo check