5 stable releases

3.0.0 Nov 16, 2023
1.0.3 Oct 29, 2023
1.0.2 Nov 11, 2022
1.0.1 Nov 10, 2022
1.0.0 Nov 9, 2022

#1696 in Parser implementations

Download history 6/week @ 2024-02-26 5/week @ 2024-03-11 75/week @ 2024-04-01

80 downloads per month

Apache-2.0

8KB
88 lines

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;
}

Dependencies

~5–13MB
~124K SLoC