Просмотр исходного кода

Write a configuration to a file

Samuel W. Flint 4 лет назад
Родитель
Сommit
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(())
+}