Rust 00 环境安装

一、安装

1 mac 、Linux 、another Unix-like os

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

1 stable 最稳定和可靠的版本

2 Nightly 每天构建的最新版本

安装 rustup install stable/nightly
切换 rustup default stable/nightly

二、命令操作

1 更新Rust

rustup update

2 卸载

rustup self uninstall

3 添加组建

rustup component add rustfmt

4 查看版本

rustup --version

三、Rust 编程语言的编译器rustc

1 查看版本

rustc --version

2 编译生成二进制文件

rustc -o output_filename filename.rs

3 编译生成库文件

rustc --crate-type lib filename.rs

四、Rust 的包管理工具Cargo

1 隐式地使用rustc 进行编译
2 命令
  • 创建
cargo new project_name

目录结构

cargo new --lib project_name
  • 构建项目(生成二进制可执行文件或库文件)
cargo build

为生成优化的可执行文件,常用于生产环境

cargo build --release 
  • 检测
cargo check
  • 运行/测试(会隐式的使用这个Rust进行编译)
cargo run/cargo test
3 Cargo.toml 文件
  • package 

设置项目名

版本

  • dependencies

设置依赖

[build-dependencies]列出了在构建项目是需要的依赖项

[dev-dependencies] 列出了只在开发时需要的依赖项

五、Cargo 插件 cargo-edit

1 安装

cargo install cargo-edit

2 添加库

cargo add dependency_name

3 安装指定版本

cargo add dependency_name@1.2.3

4 添加开发时用的依赖库

cargo add --dev dev_dependency_name

5 添加构建时用的依赖库

cargo add --build_dependency_na-me

6 删除库

cargo rm dependency_name
  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值