浏览代码

Write a configuration to a file

Samuel W. Flint 4 年之前
父节点
当前提交
816a4f0596
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      src/config.rs

+ 7 - 0
src/config.rs

@@ -97,3 +97,10 @@ pub fn read_configuration_file(filename: PathBuf) -> Config {
         Ok(s) => return toml::from_str(&s).unwrap()
     }
 }
+
+pub fn write_configuration_file(filename: PathBuf, configuration: Config) -> std::io::Result<()> {
+    let toml = toml::to_string(&configuration).unwrap();
+    let mut file = File::create(filename)?;
+    file.write_all(toml.as_bytes())?;
+    Ok(())
+}