2 个版本

0.1.1 2020 年 8 月 5 日
0.1.0 2020 年 7 月 31 日

解析器实现 中排名 2740

每月下载量 29
2 个crate中使用(通过mmdb_server

MIT 许可证

11KB
153

Build Status crates-badge

configster

Rust 解析配置文件库

配置文件格式

'option' 可以是任何没有空白的字符串。

arbitrary_option = false
max_users = 30

等号后面的选项值可以有 "attributes",它们由分隔符分隔。分隔符在调用 parse_file() 时指定

parse_file("./config_test.conf", ',')
option = Blue, light, shiny
# option = nothing, void, empty, commented_out

选项不一定要跟值。它可以用来禁用默认功能。

FeatureOff

API

调用 parse_file() 将返回一个包含每个配置文件选项行的 OptionProperties 结构体的单向量。值的属性存储在 "Value" 结构体内部的向量中。

#[derive(Debug, PartialEq)]
pub struct Value {
    pub primary: String,
    pub attributes: Vec<String>,
}

#[derive(Debug, PartialEq)]
pub struct OptionProperties {
    pub option: String,
    pub value: Value,
}

示例代码

/// use std::io;
///
/// fn main() -> Result<(), io::Error> {
///
///     let config_vec = configster::parse_file("./config_test.conf", ',')?;
///
///     for i in &config_vec {
///         println!("Option:'{}' | value '{}'", i.option, i.value.primary);
///
///         for j in &i.value.attributes {
///             println!("attr:'{}`", j);
///         }
///         println!();
///     }
///     Ok(())
/// }

请参阅 docs.rs/configster/ 以获取生成的 API 文档。

贡献

请参阅 CONTRIBUTING.md

无运行时依赖