Pārlūkot izejas kodu

Write a configuration to a file

Samuel W. Flint 4 gadi atpakaļ
vecāks
revīzija
816a4f0596
1 mainītis faili ar 7 papildinājumiem un 0 dzēšanām
  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(())
+}