diff --git a/src/settings/mod.rs b/src/settings/mod.rs index b94a164..95a405b 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -188,7 +188,7 @@ fn write_settings() { version: "1" categories: [] rules: []"#; - utils::write_file(&path, serde_yaml::to_string(&s).unwrap()).unwrap(); + utils::write_file(&path, &serde_yaml::to_string(&s).unwrap()).unwrap(); assert_eq!(settings, utils::read_file(&path).unwrap()); } diff --git a/src/settings/utils.rs b/src/settings/utils.rs index e0aeda0..557c449 100644 --- a/src/settings/utils.rs +++ b/src/settings/utils.rs @@ -44,7 +44,6 @@ pub fn read_file(path: &Path) -> Result { } } -pub fn write_file(path: &Path, content: String) -> Result<()> { /// Write a `String` into a file /// /// # Example @@ -54,6 +53,10 @@ pub fn write_file(path: &Path, content: String) -> Result<()> { /// let path = std::path::Path::new("./path/to/my/file.txt"); /// lang_evolve_core::settings::utils::write_file(&path, &content).unwrap(); /// ``` +pub fn write_file(path: &Path, content: &S) -> Result<()> +where + S: std::string::ToString, +{ use std::io::prelude::*; let mut file = match File::create(&path) { Err(e) => { @@ -62,7 +65,7 @@ pub fn write_file(path: &Path, content: String) -> Result<()> { } Ok(file) => file, }; - match file.write_all(content.as_bytes()) { + match file.write_all(content.to_string().as_bytes()) { Err(e) => { warn!( "Could not write settings to file {}: {}",