Rust中的Cargo配置文件为TOML,这里通过一些文档简单学习了一下;
TOML学习
文档:
- https://rustwiki.org/wiki/rust-related/toml/
- https://toml.io/en/v1.0.0
- https://github.com/LongTengDao/TOML/blob/%E9%BE%99%E8%85%BE%E9%81%93-%E8%AF%91/toml-v1.0.0.md
工具:
- JSON转TOML:https://tooltt.com/json2toml/
- TOML转JSON:https://tooltt.com/toml2json/
简而言之,用 [table] 表的形式来归并多个配置,并且去掉了 JSON 括号的形式或者 YAML 缩进的形式;
下面是一个例子:
1 | # 单个配置 |
对应的JSON:
1 | { |
Rust中的Cargo配置
在 Rust 圣经中展示了 Cargo 的配置:
可以看到 Cargo Target 列表:(查看 Target 配置 获取详细设置)
[lib\]— Library target 设置.[[bin\]]— Binary target 设置.[[example\]]— Example target 设置.[[test\]]— Test target 设置.[[bench\]]— Benchmark target 设置.
可以看到,库的定义为表:[lib],而其他配置例如 [[bin]] 则为表数组;
这是正好对应了Rust中的规定:
一个 Crate 中只能定义一个 lib 对象,但是可以在 Cargo.toml 中创建多个 bin、example 对象;