学习rust(二)cargo和包
# 使用cargo管理项目
## 1 软件包管理
cargo
## 2 模块
定义模块 pub xxx x1;
使用模块user xxx::xx;
文件可以作为模块
目录也可以作为模块
模块的导入
1. use crate::
2. 相对导入 self:xx super::
目录可以作为模块
## 3 cargo和程序库
cargo new (--lib)
cargo依赖
1. cargo update
2. cargo update -p crate-name
cargo的版本的说明: major,minor,patch
cargo test测试
1. #[test] #[cfg(test)]
cargo工作区
## 4 cargo扩展工具
cargo-watch 监控项目变化自动编译
cargo-edit 编辑依赖项
cargo-deb deb上运行
cargo-outdated 过时的软件依赖项
clippy格式化代码
cargo.toml
1. package 清单
2. package.metadata.settings元数据警告
3. features
4. dependencies 依赖
1. ^版本范围
2. 支持{git=xx,branch=xx}
5. build-dependencies
## 5 rust的环境
rustfmt格式化
clippy 潜在问题
racer竞争检测
## 6 项目聚合
通过workspace聚合项目
```
[workspace]
members = [
"app",
"my_crate"
]
```
## 7 如何使用go的模块呢?
```rust
// 相对路径
say::hello();
// 绝对路径调用
crate::say::hello();
// 重导出名称
people::hi::hi_1();
people::hello();
```