Browse Source

Write a configuration to a file

Samuel W. Flint 4 năm trước cách đây
mục cha
commit
816a4f0596
1 tập tin đã thay đổi với 7 bổ sung0 xóa
  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(())
+}