https://github.com/yzqdev/rust-proj
https://github.com/yzqdev/rust-proj
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/yzqdev/rust-proj
- Owner: yzqdev
- License: mit
- Created: 2022-05-03T06:17:28.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-05T05:51:57.000Z (over 1 year ago)
- Last Synced: 2025-08-01T14:24:01.514Z (11 months ago)
- Language: Rust
- Size: 19.5 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rust教程
## cargo workspace
直接在顶部的Cargo.toml添加
```toml
[workspace]
members = [
"adder",
]
```
然后
### 创建二进制
```shell
cargo new adder
```
运行`cargo build`构建工作空间
```text
├── Cargo.lock
├── Cargo.toml
├── adder
│ ├── Cargo.toml
│ └── src
│ └── main.rs
└── target
```
### 创建lib
```shell
cargo new add_one --lib
```
为了在顶层 add 目录运行二进制 crate,可以通过 -p 参数和包名称来运行 cargo run 指定工作空间中我们希望使用的包
```shell
cargo run -p adder
# 添加参数
cargo run -p cli-tool -- example
```
测试
```shell
cargo test -p add_one
```
一些shell
```
cargo run --package study --bin study
# 简写
cargo run --bin study
cargo build --release --bin study
# 运行命令行程序
cargo run --bin rcli -- params1 params2
## 添加依赖
cargo add md-5 -p guessing_game
```