跳至主要內容
Rust开发环境搭建

Rust开发环境搭建

TaoChenyue...小于 1 分钟

安装

On Linux/macOS

curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh

Rust依赖GCC/Clang,如果是Ubuntu可以装build-essential

sudo apt install build-essential

On Windows

对WSL来说,和Linux安装一样。也可以去官网open in new window下32/64位可执行程序。

Rust操作

#查看版本
rustc --version
#更新版本
rustup update
#卸载
rustup self uninstall
#查看API文档
rustup doc
#编译文件
rustc <file>

Cargo(项目管理工具)操作

#创建项目
cargo new <project-name> 
#检查错误
cargo check
#编译项目,默认debug模式
cargo build
#编译项目,指定release模式
cargo build --release
#编译+运行项目
cargo run

Cargo.toml跟pyproject.toml类似,是项目配置文件,可以配置编译参数,依赖库等。

Hello World

// main.rs
fn main() {
    println!("Hello, world!");
}

参考

评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.8