iceyee_config

Crates.ioiceyee_config
lib.rsiceyee_config
version3.0.0
sourcesrc
created_at2022-11-09 06:07:12.994355
updated_at2023-11-16 03:43:22.778252
descriptionConfig file parser.
homepage
repositoryhttps://github.com/iceyee/rust_iceyee/tree/main/iceyee_config/
max_upload_size
id708580
size9,071
Iceyee (iceyee)

documentation

README

iceyee_config

读写配置.

Supported Os

  • linux
  • macos
  • windows

Example

const JSON: &str = "
{
    \"a\": 1,
    \"b\": 2
}
";
const YAML: &str = "
    a: 3
    b: 4
";

#[tokio::test]
pub async fn test_config() {
    use iceyee_config::ConfigParser;
    use serde::Deserialize;
    use serde::Serialize;
    #[derive(Debug, Serialize, Deserialize)]
    struct A {
        a: usize,
        b: usize,
    }
    println!("");
    // 写入数据.
    tokio::fs::write("/tmp/test.json", JSON.as_bytes())
        .await
        .unwrap();
    tokio::fs::write("/tmp/test.yaml", YAML.as_bytes())
        .await
        .unwrap();
    // 读配置, 验证.
    let mut buffer: String = String::new();
    let a: A = ConfigParser::read("/tmp/test.json", &mut buffer)
        .await
        .unwrap();
    assert!(a.a == 1);
    assert!(a.b == 2);
    let a: A = ConfigParser::read("/tmp/test.yaml", &mut buffer)
        .await
        .unwrap();
    assert!(a.a == 3);
    assert!(a.b == 4);
    return;
}
Commit count: 0

cargo fmt