2个版本

使用旧的Rust 2015

0.1.1 2019年6月18日
0.1.0 2018年1月1日

#1655编码

MIT/Apache

31KB
554

repomon


lib.rs:

repomon的配置管理。

示例

从TOML字符串读取

#
#
#
#
    let test_toml = r#"basedir = "/home/jozias/projects"

    [[repos.ar2.remotes]]
    name = "origin"
    url = "[email protected]:repos/ar2.git"

    [[repos.ar2.branch]]
    name = "master"
    interval = "1m"
    remotes = ["origin"]

    [[repos.repomon.remotes]]
    name = "origin"
    url = "[email protected]:repos/repomon.git"

    [[repos.repomon.remotes]]
    name = "gh"
    url = "[email protected]:rustyhorde/repomon.git"

    [[repos.repomon.branch]]
    name = "master"
   interval = "1m"
    remotes = ["origin", "gh"]

    [[repos.repomon.branch]]
    name = "feature/testing"
    interval = "1m"
    remotes = ["origin", "gh"]
    "#;

    // Serialize the TOML above into a `Repomon` struct.
    let mut reader = Cursor::new(test_toml);
    let repomon = read_toml(&mut reader)?;

    // Check the `Repomon` struct.
    let repos = repomon.repos();
    assert_eq!(repos.keys().len(), 2);
    assert!(repos.contains_key("repomon"));
    assert!(repos.contains_key("ar2"));

写入TOML字符串

#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
      let mut repomon: Repomon = Default::default();
      repomon.set_basedir("/home/jozias/projects".to_string());
      repomon.set_repos(repo_map);

      // Write the TOML to the given buf.
      let mut buf = [0; 5000];

      // Wrapped to drop mutable borrow.
      {
        let mut writer = Cursor::new(&mut buf[..]);
        write_toml(&repomon, &mut writer)?;
      }

      // Check that the result is the same as the TOML above.
      let filtered = buf.iter().filter(|x| **x > 0).cloned().collect::<Vec<u8>>();
      assert_eq!(
          TEST_TOML,
          String::from_utf8(filtered).expect("Invalid UTF-8 in result")
      );

依赖

~9.5MB
~223K SLoC