rust出顾茅庐,安装篇(一)

mac系统开发

1.安装rust环境

rust 官网安装
https://www.rust-lang.org/zh-CN/tools/install
rust 文档资料: https://kaisery.github.io/trpl-zh-cn/
https://github.com/KaiserY/trpl-zh-cn/tree/main?tab=readme-ov-file
中文社区: https://rustcc.cn/
工作机会:https://rustjobs.dev/
rust官方库: https://crates.io/
jike
练手项目

brew upgrade

brew install rustup-init

进入/opt/homebrew/Cellar/rustup-init/1.23.1/bin

运行 rustup-init

在这里插入图片描述
然后有3个默认选项, 我选择第一个默认安装, 2 是自定义安装, 3 是取消安装

屏幕出现成功字样 Rust is installed now. Great!
最后执行这句,让环境变量生效 source $HOME/.cargo/env

安装好了后执行,并查看版本

rustc -V       
rustc 1.63.0 (4b91a6ea7 2022-08-08)
或者
rustc --version
rustc 1.63.0 (4b91a6ea7 2022-08-08)

2.创建 rust 项目

cargo new hello
在hello项目里面 cargo build ,会在 target/debug 生成二进制名字

cargo run ,会在线运行项目

3.代理配置

vim $HOME/.cargo/config.toml
[http]
proxy="127.0.0.1:7890"
// 重新打开终端
cargo install crm // 安装进度条

4.开发坏境搭建

  • vscode插件
  • rust-analyzer
  • Error Lens

5.创建项目

·隐式地使用rustc进行编译
·命令
·创建
cargo new project_name
·cargo new--lib project_name创建一个新的Rust库项目的
·构建项目(生成二进制可执行文件或库文件)
·cargo build
·cargo build-release为生成优化的可执行文件,常用于生产环境
·检测
·cargo check
·运行/测试
cargo run/cargo test

6.依赖添加

官方包地址:https://crates.io/

Cargo插件cargo-edit
安装
cargo install cargo-edit

添加库
cargo add dependency_name
安装指定版本
cargo add dependency_name@1.2.3

添加开发时用的依赖库
cargo add --dev dev_dependency_name
添加构建时用的依赖库
cargo add --build build dependency_name
删除库
cargo rm dependency_name

7.镜像源

https://rsproxy.cn/#getStarted

8.Cargo.toml 依赖和一些配置

运行: cargo run --bin app7_1
编译稳定版: cargo build --bin app7_1 -r
[dependencies]
# 依赖包
rand = "0.8.5"

[[bin]]
# 指定多个可执行文件 cargo run --bin main
name = "main"
path = "src/main.rs"

[[bin]]
# cargo run --bin app3_1
name = "app3_1"
path = "src/app3.1/main.rs"

[[bin]]
name = "app3_2"
path = "src/app3.2/main.rs"


[lib]
name = "app7_1_lib"
path = "src/app7.1/lib.rs"

8.一些常用的宏

#[allow(unused)] - 未使用
 #[derive(Debug)] - {:#?} 打印
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gitxuzan_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值