2 个不稳定版本
| 0.2.0 | 2021年2月17日 | 
|---|---|
| 0.1.0 | 2021年2月13日 | 
#2597 in 解析器实现
16KB
318 行
dfconfig-rs
为 Dwarf Fortress 提供的配置/init 文件解析器。
是什么?
DF 配置文件格式解析器的纯 Rust 实现,尽量与游戏内部实现一致。更多详细信息请参阅 文档。
为什么?
我需要为我的其他项目创建一个 DF 配置解析器/操作器。还有,无聊。
如何?
此库托管在 crates.io 上,因此在使用您的项目中使用它非常简单
[dependencies]
dfconfig = "0.1"
贡献
欢迎 Pull Requests。
lib.rs:
dfconfig 是一个库,用于解析和操作 Dwarf Fortress 的 init.txt 和 d_init.txt 配置文件(以及可能使用相同格式的许多其他文件)。此库的功能已被特别定制,以便与 DF 内部解析器类似,这意味着
- Config::get返回最后一个出现值,如果配置指定了键多次。
- 行首不允许有空格,任何不以 [字符开始的行都被视为注释。
解析器保留所有解析的字符串内容,包括空行和注释。
示例
use std::fs::{read_to_string, write};
use dfconfig::Config;
// Parse existing config
let path = r"/path/to/df/data/init/init.txt";
let mut conf = Config::read_str(read_to_string(path)?);
// Read some value
let sound = conf.get("SOUND");
// Modify and save the config
conf.set("VOLUME", "128");
write(path, conf.print())?;
依赖项
~2.2–3MB
~54K SLoC